4

To support iCloud, we're encouraged to use a UIDocument subclass. If I define a new subclass, set the project target version to 3.0, and test using for iOS 5 before using my new subclass, will the code work on iOS 4 or does linking in a subclass break backwards compatibility?

Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83
wordy
  • 539
  • 5
  • 15

2 Answers2

2

UIKit can be weak-linked, but the results would be undefined if you tried to initialize a UIDocument or UIDocument subclass. You would need something like:

if (NSStringFromClass(@"UIDocument")) 
{
    ...
}

That would make it totally useless for your purposes. So the answer to your question is no, any code involving UIDocument would not run, but you could put conditional checks around such code. You're better off finding an alternative method for saving data.

Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83
  • Thanks for the answers. I didn't want to use UIDocument on iOS4, just wasn't sure if I could define a iOS5 subclass without making the whole program fail to launch on previous versions. My understanding of your helpful answers is that it should be OK as long as I make sure UIKit is weak linked (+ check for version or class existence before actually using it), so that seems like the right general solution for implementing iCloud features in a backwards-compatible way. – wordy Nov 01 '11 at 15:09
  • Done. Actually default link settings work fine (new code is weak linked autiomatically) as long as you set the right Xcode target (e.g. OS 3.1). Have confirmed this works, though be careful to also manually weak link libSystem.dylib or the code built with the latest XCode will crash on OS 3.x (because of "blocks") – wordy Dec 26 '11 at 20:35
0

It will need to link with UIDocument in order to understand what subclassing UIDocument actually means. For example, if you have class Bar which subclasses Foo, and Foo has method 'doBaz', you can call 'doBaz' on a Bar instance, but if the linker doesn't know Foo, it doesn't know Bar can doBaz.

You may be able to do a weak link though. There was a similar situation when iOS 4 came out, with iAds not being available in iOS 3, which was the best on iPad at the time.

wjl
  • 7,143
  • 1
  • 30
  • 49
  • It depends if UIDocument can be weak-linked. Since it's part of UIKit, then I think yes, no. – wjl Nov 01 '11 at 04:23