Bas*_*Bas 4 darwin uikit ios swift
我正在键入一些Swift代码,因为我很无聊并且一段时间没有编写Swift.
当我包含UIKit时,为什么这段代码有用呢?
import UIKit
public class foo {
private var boolTest : Bool?
init() {
boolTest = true
}
public func call() -> AnyObject? {
if let bool = boolTest {
return bool
}
else {
return nil
}
}
}
foo().call()
Run Code Online (Sandbox Code Playgroud)
当我导入Darwin而不是UIKit时,它不起作用.
import Darwin
public class foo {
private var boolTest : Bool?
init() {
boolTest = true
}
public func call() -> AnyObject? {
if let bool = boolTest {
return bool
}
else {
return nil
}
}
}
foo().call()
Run Code Online (Sandbox Code Playgroud)
除了我将UIKit改为达尔文之外,它的代码完全相同.错误说不能将类型bool返回给AnyObject?
当我包含UIKit时,它不会给出错误消息.
那么有谁知道是什么原因造成的?
Foundation从添加了自动桥接Bool至NSNumber(这是一个AnyObject).
extension Bool : _ObjectiveCBridgeable {
public init(_ number: NSNumber)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
113 次 |
| 最近记录: |