Getting list of classes inside NSBundle

  • Is there a way for me to get a list of all classes that an NSBundle
    contains?  I only see two methods listed on NSBundle that are close to what
    I need (principalClass and classNamed:) and both require me to already know
    the name of the class I want to load.  What I'm trying to do is get a list
    of classes inside a bundle (which I may not know the contents of) and print
    out the class names of the ones that match a certain criteria.

    Thanks,
    Jason
    **
  • On Oct 19, 2007, at 11:28 AM, Jason wrote:

    > Is there a way for me to get a list of all classes that an NSBundle
    > contains?  I only see two methods listed on NSBundle that are close
    > to what
    > I need (principalClass and classNamed:) and both require me to
    > already know
    > the name of the class I want to load.  What I'm trying to do is get
    > a list
    > of classes inside a bundle (which I may not know the contents of)
    > and print
    > out the class names of the ones that match a certain criteria.

    When NSBundle loads a bundle, it sends out an
    NSBundleDidLoadNotification, attached to which is a list of the
    loaded classes (under the NSLoadedClasses key).  If you want to get
    information about the class content of a bundle without having to
    load it, I'm afraid you'll have to examine the executable yourself.

    Douglas Davidson
  • On Friday, October 19, 2007, at 02:30PM, "Jason" <jsallis...> wrote:
    > Is there a way for me to get a list of all classes that an NSBundle
    > contains?

    Yes.The userInfo dictionary of the NSBundleDidLoadNotification contains the information you require:

    @"NSLoadedClasses"
    An NSArray object containing the names (as NSString objects) of each class that was loaded

    See: http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes
    /NSBundle_Class/Reference/Reference.html#//apple_ref/c/data/NSBundleDidLoad
    Notification
  • Oh, I have no problem with having to load it.  I assumed that I would have
    to, and it looks like once I do, I'll be up and running.  Thanks to everyone
    for the quick replies!

    On 10/19/07, Douglas Davidson <ddavidso...> wrote:
    >
    >
    > On Oct 19, 2007, at 11:28 AM, Jason wrote:
    >
    > Is there a way for me to get a list of all classes that an NSBundle
    >
    > contains?  I only see two methods listed on NSBundle that are close to
    > what
    >
    > I need (principalClass and classNamed:) and both require me to already
    > know
    >
    > the name of the class I want to load.  What I'm trying to do is get a list
    >
    > of classes inside a bundle (which I may not know the contents of) and
    > print
    >
    > out the class names of the ones that match a certain criteria.
    >
    >
    > When NSBundle loads a bundle, it sends out an NSBundleDidLoadNotification,
    > attached to which is a list of the loaded classes (under the NSLoadedClasses
    > key).  If you want to get information about the class content of a bundle
    > without having to load it, I'm afraid you'll have to examine the executable
    > yourself.
    >
    > Douglas Davidson
    >
    >
  • Am 19.10.2007 um 20:42 schrieb Jason:
    > Oh, I have no problem with having to load it.  I assumed that I
    > would have
    > to, and it looks like once I do, I'll be up and running.  Thanks to
    > everyone
    > for the quick replies!

      Just in case you're not aware: There's a +load method that gets
    called on every class when it's loaded. If you want this list so you
    can register certain classes with a central registry, it might be
    more elgant, efficient and easier to just have a +load method that
    adds [self class] to your registry.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • On Oct 19, 2007, at 3:57 PM, Uli Kusterer wrote:

    > Am 19.10.2007 um 20:42 schrieb Jason:
    >> Oh, I have no problem with having to load it.  I assumed that I
    >> would have
    >> to, and it looks like once I do, I'll be up and running.  Thanks
    >> to everyone
    >> for the quick replies!
    >
    > Just in case you're not aware: There's a +load method that gets
    > called on every class when it's loaded. If you want this list so
    > you can register certain classes with a central registry, it might
    > be more elgant, efficient and easier to just have a +load method
    > that adds [self class] to your registry.

    Not sure if that is as good of an idea - from the docs:

    Due to the amount of uncertainty about the environment at the point
    that load is invoked, you should avoid using load whenever possible.

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium2 | build, mutate, evolve, animate  | images, textures,
    fractals, art
  • Am 19.10.2007 um 23:51 schrieb glenn andreas:
    > Not sure if that is as good of an idea - from the docs:
    >
    > Due to the amount of uncertainty about the environment at the point
    > that load is invoked, you should avoid using load whenever possible.

      Well, this is mitigated a lot for loadable bundles, though. There,
    you're pretty much guaranteed that the app has already been loaded,
    you just shouldn't use any other classes in your bundle yet. But
    getting your own class object and adding it to an NSMutableArray in
    the app itself is hunky-dory.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • On Oct 19, 2007, at 5:00 PM, Uli Kusterer wrote:

    > Am 19.10.2007 um 23:51 schrieb glenn andreas:
    >> Not sure if that is as good of an idea - from the docs:
    >>
    >> Due to the amount of uncertainty about the environment at the
    >> point that load is invoked, you should avoid using load whenever
    >> possible.
    >
    > Well, this is mitigated a lot for loadable bundles, though. There,
    > you're pretty much guaranteed that the app has already been loaded,
    > you just shouldn't use any other classes in your bundle yet. But
    > getting your own class object and adding it to an NSMutableArray in
    > the app itself is hunky-dory.

    Which will work fine and dandy up until the point where you decide
    that you're going to migrate that plugin class into the app itself
    (since you've decided that it is so wonderful that should be part of
    the app itself instead of a plugin).

    Personally, rather than keeping track of a class list as things are
    loaded, I'd just walk the entire class lists as needed (which would
    also help to mitigate against forgetting to add your magic
    registration into +load).

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium2 | build, mutate, evolve, animate  | images, textures,
    fractals, art
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today