Swift3还支持__conversion吗?

时间:2016-10-18 12:42:40

标签: swift implicit-conversion

根据this question我在Swift的操场上试过

extension Double {
  func __conversion() -> UInt8 { return UInt8(self) }
  func __conversion() -> Int { return Int(self) }
  // add more if you need to
}

var d = 1.0
var u8 : UInt8 = d

但这只会产生一个堆栈跟踪:

  

Playground执行失败:错误:MyPlayground.playground:8:18:错误:无法转换类型' Double'指定类型' UInt8'   var u8:UInt8 = d                   ^                   UInt8()

     
      
  • 线程#1:tid = 0xa5e495,0x000000010f86e360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground,queue =' com.apple.main-thread`,stop reason = breakpoint 1.1
  •   
  • frame#0:0x000000010f86e360 com.apple.dt.Xcode.PlaygroundStub-macosx' executePlayground
  •   
     

...

     

第51帧:0x00007fffbce3a6b9 ViewBridge`- [NSXPCSharedListener简历] + 16

     

第52帧:0x00007fffbce152c9 ViewBridge`NSViewServiceApplicationMain + 3022

     

第53帧:0x000000010f86e3a2 com.apple.dt.Xcode.PlaygroundStub-macosx`main + 34

     

帧#54:0x00007fffbecf8255 libdyld.dylib`start + 1

这是一个错误吗?对__conversion的支持是否默默终止(我读过类似Swift1的内容)?

0 个答案:

没有答案
相关问题