Re: How to use a class, which may not be available
Re: How to use a class, which may not be available
- Subject: Re: How to use a class, which may not be available
- From: Philippe Mougin <email@hidden>
- Date: Sat, 31 Jan 2004 03:58:00 +0100
> Since never occurred previously, soma advice is needed.
> If I would like to use
>
> NSSortDescriptor
>
> which is availbale on 10.3 as base of some new class
> , but not before, how do I have to code, such that
> my code will not crash.
>
> In a 10.2 environment, the respective part of code - which
> uses the SortDescriptor -will not be called. Thus, no
> problem regarding message dispatching should occur.
> Since some 10.3 callback will not be called in 10.2.
>> But how about linking? Will the app crash due to
> unresolved symbols?
The following technique is easy to use and works well. The idea is to
put your panther specific subclass in a separate bundle that you will
dynamically load when running on Panther (or later).
In Xcode:
1) Create a new target inside your project (menu Project >> New
Target). Choose Cocoa loadable bundle for the type of your target. Name
your target something like "PantherAndLaterOnly".
2) Make the other targets in your project dependent of your new target,
where needed. You can do that from the target inspector panel of each
target.
3) Ensure that your new bundle is embedded inside your other targets by
dragging your new bundle (from the "Product" folder, in the "Group &
Files" tree) to the "Bundle Resources" folder of each other target
(found in the "Targets" entry in the "Group & Files" tree).
4) Associate your Panther specific subclass with your new target.
5) In your existing code, check if you are running on Panther or later.
If this is the case, load your Panther specific code with something
like:
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_2)
{
// 10.3 or later system
[[NSBundle bundleWithPath:[[NSBundle mainBundle]
pathForResource:@"PantherAndLaterOnly" ofType:@"bundle"]] load];
}
6) You can now happily use your Panther specific code. For instance, if
your subclass is named MyPantherSpecificSubclass you can get it with:
NSClassFromString(@"MyPantherSpecificSubclass")
Best,
Philippe Mougin
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.