Question

My code has a class in it (let's call it myRefLib) that inherits from UIReferenceLibraryViewController (part of UIKit Framework) which is a class that is only available in iOS 5 and above. I would like to have a deployment target of iOS 3.2.

If i was just creating an instance of the UIReferenceLibraryViewController, I understand I can use a base SDK of 5 and then test if the class exists with [UIReferenceLibraryViewController class] before running any code that includes it. But how do I do it if I'm inheriting from the class?

The issue is that I have to #include the inheriting class myRefLib for the parts of my code that will use it - but there is no way to conditionally do that at runtime. Alternatively there is also no way of runtime conditionally inheriting from UIReferenceLibraryViewController in myRefLib. I'd also like to make an instance of myRefLib a property of another class - again, how can I do that runtime conditionally?

Any help much appreciated ...

D

Was it helpful?

Solution

Well, first of all, you have know what you're going to do when running on the earlier OS. Basically, you have to write your code as though you were building against the iOS 3.2 SDK. Only then can you add optional enhancements using the newer features.

Starting with the easiest thing: you don't need a declaration of a class interface in order to declare variables, including instance variables, as pointers to that class. You just need a forward declaration:

@class SomeClass;
SomeClass* foo;

Next, there should be no problem with importing a header which defines your class. That's a compile-time thing, which you seem to think is a problem, but which means it's not affected by the runtime environment. It will compile because you're building against the iOS 5.0 SDK.

The thing you have to be careful of is to not use the class if it's not available. You already know how to check that: test if [SomeClass class] returns Nil. If it does, don't instantiate your custom subclass.

Finally, you mention "runtime conditionally inheriting from UIReferenceLibraryViewController in myRefLib". Why do you think you need to do that? If UIReferenceLibraryViewController is not available, then it doesn't make much sense to want to use myRefLib which subclasses it. If you have some alternative implementation in mind that doesn't depend on UIReferenceLibraryViewController, then make a separate class. Then conditionally pick between myRefLib and this other class depending on availability.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top