以下是导致问题的简单代码:
class CoreViewController: UIViewController {
private let isPad = UI_USER_INTERFACE_IDIOM() == .Pad
}
以下是erorr消息
< unknown&gt ;:0:错误:IR生成失败:程序太聪明:变量与现有符号碰撞OBJC_CLASS _ $ _ UIDevice
如果我删除UI_USER_INTERFACE_IDIOM() == .Pad
有什么想法吗?
答案 0 :(得分:2)
我相信UI_USER_INTERFACE_IDIOM是一个宏。它可能不适用于Swift。
答案 1 :(得分:2)
UI_USER_INTERFACE_IDIOM
将 NOT 在Swift中工作,它是一个Objective-C宏。
选项1。改为使用UIDevice.currentDevice().userInterfaceIdiom
。
switch UIDevice.currentDevice().userInterfaceIdiom {
case .Phone:
// It's an iPhone
case .Pad:
// It's an iPad
case .Unspecified:
// Undefined
}
选项2。请求UITraitCollection
个实例并检查成语(推荐)
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
}