• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to use a class, which may not be available
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: NSArrayController Funkyness
  • Next by Date: User Setting Primary Identifier in Address Book
  • Previous by thread: Re: How to use a class, which may not be available
  • Next by thread: How to trap app crashes
  • Index(es):
    • Date
    • Thread