Reputation: 8960
I'm creating an app that works with CloudKit framework (iOS 8-only) but still want to keep compatibility with iOS 7.1, with no CloudKit functionality, of course. Apple documentation recommends checking for optional classes like this:
if ([CKRecordID class]) {
// iOS 8 code
} else {
// iOS 7 code
}
This works. On the other hand, if I write
@interface Foo : NSObject
@property (nonatomic) CKRecordID *recordID;
@end
anywhere in the code, the app will crash on iOS 7 when loading the Foo
class. How can I define properties with those optional classes?
Upvotes: 1
Views: 82
Reputation: 3955
You can make your property recordId
of type id or NSObject
.
And when you need to access this property (after checking that your runtime is iOS8+), you cast it to CKRecordID
class.
Upvotes: 1
Reputation: 20145
You could use the forward declaration
@class CKRecordID;
but you will need runtime checks for the iOS version, such as
[[NSProcessInfo processInfo] operatingSystemVersion]
Other solutions for detecting the iOS version are shown here or here.
But how about two different builds for different iOS versions?
Upvotes: 1