Search code examples
iosswiftnscalendarunrecognized-selector

Unrecognized selector sent to class [NSCalendar calendarWithIdentifier]


I have an application written in Swift which runs fine on the iOS simulator. The target for the project is set to iOS 7.1.

When I run the app on my iPhone 5s, it crashes at the following line:

let calendar = NSCalendar(identifier: NSGregorianCalendar)

with the error:

+[NSCalendar calendarWithIdentifier:]: unrecognized selector sent to class 0x1955eee60

Do I have to make a different call for iOS8 vs. iOS7.x?


Solution

  • Even though using NSCalendar(identifier: NSGregorianCalendar)doesn't throw an error at compile time, what might be a bug, I suppose using NSCalendar(calendarIdentifier: NSGregorianCalendar) as stated in the docs.