Manish Verma
Manish Verma

Reputation: 539

<unknown>:0: error: IR generation failure: program too clever: variable collides with existing symbol OBJC_CLASS_$_UIDevice

unknown:0: error: IR generation failure: program too clever: variable collides with existing symbol OBJC_CLASS_$_UIDevice

This is the error message thrown by Xcode 7.0.1. I have no idea, what I did wrong to make Xcode throw this error. This error occurs when I try to build my project in swift.

enter image description here

Upvotes: 2

Views: 394

Answers (2)

Lockerios
Lockerios

Reputation: 79

As used in a constant file. You may use something like this also

let IS_IPAD = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad)
let IS_IPHONE = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Phone)

In the Apple document, we may find this

The UI_USER_INTERFACE_IDIOM() function is provided for use when deploying to a version of the iOS less than 3.2. If the earliest version of iPhone/iOS that you will be deploying for is 3.2 or greater, you may use -[UIDevice userInterfaceIdiom] directly.

This is why we get error below

IR generation failure: program too clever: variable collides with existing symbol OBJC_CLASS_$_UIDevice

To solve this, just replace with this code

let IS_IPAD = UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad
let IS_IPHONE = UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone

Enjoy :)

Upvotes: 6

matt
matt

Reputation: 534950

Use a static property of a struct, like this:

struct Constants {
    static let iOSVersion = UIDevice.currentDevice().systemVersion
}

Now you can say Constants.iOSVersion anywhere in your program.

Upvotes: 0

Related Questions