I was typing some Swift code because I was bored and didn't program Swift after a while.
Why does this code work when I turn on 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()
And when I import Darwin instead of UIKit, it does not work.
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()
This is the same code, except that I changed UIKit to Darwin. The error says that you cannot return the bool type in AnyObject?
It does not give an error message when I turn on UIKit.
Does anyone know what causes this?
source
share