Re: What defines if an objective C class is visible outside a bundle?
Re: What defines if an objective C class is visible outside a bundle?
- Subject: Re: What defines if an objective C class is visible outside a bundle?
- From: Christiaan Hofman <email@hidden>
- Date: Tue, 09 Oct 2012 13:59:58 +0200
On Oct 9, 2012, at 12:33, Jon Hodgson wrote:
> Thanks,
>
> It certainly helps explain how things work, but maybe you can offer
> some more information on how to find the problem.
>
> From what you said I think classNamed is basically an NSBundle load
> followed by a ClassFromName (the NSBundle load I put in there was
> redundant, I just wanted to check it was loading the bundle ok).
>
> Anyway, how do I find out what classes are available? Maybe if I could
> dump them out this might give me a clue.
>
You can look at the NSBundleDidLoadNotification notification, which reports the classnames that are loaded through the NSLoadedClasses key in the user info.
> Also, are all objective C classes in a bundle automatically visible
> systemwide, or only specific ones? From what you say it seems all of
> them?
>
I assume you don't really mean "systemwide," I assume you mean process wide.
But (Apple's implementation of) Obj-C does not have a distinction between visibility of classes, there is only a single registration of classes for each process, all class registration goes through the runtime functions, which are public.
> regards
>
> Jon
>
The only explanation to me seems to be that the class was already defined somewhere else. So can you get the class through NSClassFromString()? And why don't you want to use that? And when you have the class, you can check where it comes from using +[NSBundle bundleForClass:].
Christiaan
> On Mon, Oct 8, 2012 at 10:22 PM, Jens Alfke <email@hidden> wrote:
>>
>> On Oct 8, 2012, at 4:05 AM, Jon Hodgson <email@hidden>
>> wrote:
>>
>> NSBundle* viewBundle = [NSBundle bundleWithPath: [unescapedPath
>> autorelease]];
>> BOOL loaded = [viewBundle load]; // I put this in to check the bundle
>> was being found
>> Class viewClass = [viewBundle classNamed: viewClassName];
>>
>> Anyway, with the Juce bundle, it finds the viewClass, with mine it
>> doesn't, and I can't work out why not.
>>
>>
>> Are the class names different? Are you sure your class name is unique?
>>
>> The Objective-C runtime has a single flat per-process namespace for classes.
>> That is, class names aren’t scoped to anything like a bundle. You can think
>> of there being a global dictionary that maps class names to implementations.
>> If a loaded bundle or framework contains a class Foo, that class will be
>> available anywhere in the process by calling something like
>> NSClassFromString(@“Foo”). A corollary of this is that you can only have one
>> implementation of a class of the same name loaded at once. If there are ever
>> two definitions of a class of the same name loaded, the runtime will print a
>> warning, and which class actually gets used is undefined.
>>
>> I don’t know what the exact behavior is of -[NSBundle classNamed:] because
>> I’ve never had to use it — it isn’t necessary to ask a bundle for a class,
>> you can just as the runtime via NSClassFromString, once the bundle is
>> loaded.
>>
>> Hope this sheds some light on your problem...
>>
>> —Jens
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden