Reputation: 12198
Here is the simple code that causing problem:
class CoreViewController: UIViewController {
private let isPad = UI_USER_INTERFACE_IDIOM() == .Pad
}
Following is the erorr message
<unknown>:0: error: IR generation failure: program too clever: variable collides with existing symbol OBJC_CLASS_$_UIDevice
No error, if I remove UI_USER_INTERFACE_IDIOM() == .Pad
Any thoughts?
Upvotes: 1
Views: 46
Reputation: 40030
UI_USER_INTERFACE_IDIOM
will NOT work in Swift, it's an Objective-C macro.
Option 1. Use UIDevice.currentDevice().userInterfaceIdiom
instead.
switch UIDevice.currentDevice().userInterfaceIdiom {
case .Phone:
// It's an iPhone
case .Pad:
// It's an iPad
case .Unspecified:
// Undefined
}
Option 2. Request an UITraitCollection
instance and check the idiom (recommended)
let deviceIdiom = UIScreen.mainScreen().traitCollection.userInterfaceIdiom
switch (deviceIdiom) {
case .Pad:
// It's an iPad
case .Phone:
// It's an iPhone
case .TV:
// Apple TV
default:
// Undefined
}
Upvotes: 2
Reputation: 131418
I believe UI_USER_INTERFACE_IDIOM is a macro. It might not work from Swift.
Upvotes: 2