bundleWithIdentifier: failures

  • I'm being floored by an issue where NSBundle's bundleWithIdentifier:
    is failing to load one of my frameworks.

    I'm doing development with Xcode/IB 3.x (Mac OS X 10.5.1) and in order
    for my IB Plug-In to access images at both design-time and within the
    simulator, I created a framework containing those images.

    This worked well for my first project (Drills).  I would have a simple
    Cocoa framework installed to ~/Library/Frameworks

    The image loading code that my UI framework uses (this code is
    ultimately called from within IB itself during design time and within
    the simulator):

    + (NSImage*)imageNamed_II:(NSString*)aName
    {
        NSImage*  theImage = nil;

        if ((aName != nil) && ([aName length] > 0))
            {
            theImage = [NSImage imageNamed:aName];

            // If the image is not yet loaded, attempt to load it from
    our image frameworks

            if (theImage == nil)
                {
                NSBundle* theImageBundle =
                    [NSBundle
    bundleWithIdentifier:@"com.instantinteractive.internal.images.drills"];

                if (theImageBundle != nil)
                    {
                    NSString* theImagePath = [theImageBundle
    pathForImageResource:aName];

                    if ((theImagePath != nil) && ([theImagePath length] >
    0))
                        {
                        theImage = [[[NSImage alloc]
    initWithContentsOfFile:theImagePath] autorelease];
                        [theImage setName:aName];
                        }
                    }
                }
            }

        return theImage;
    }

    I then extended this code to include a second "if (theImage == nil)"
    block which would attempt to load the second image bundle should the
    image not be found in the first.

    But, bundleWithIdentifier is always returning nil.  I've triple-
    checked the code, verified that my image framework has a unique name,
    NSPrincipal class set correctly, that its bundle identifier is
    correct, etc.

    I even started from scratch and used a totally different bundle
    identifier.  In all cases, bringing up System Profiler indeed finds
    the second image framework and displays info about it correctly.  For
    example, names are correct and its location is also ~/Library/Frameworks

    Console doesn't show me any failures.  The name of the second
    framework also only contains English letters and has no spaces
    anywhere in its name or in its path).

    Finally, I even logged out and rebooted a couple of times to ensure
    that the system wasn't holding on to any cached version (hmm...I
    wonder if I need to purge prefs anywhere).  Still no luck.  I even
    verified that my system has only one copy of the framework (in ~/
    Library/Frameworks); i.e. I removed the copy that Xcode produced in my
    Projects folder.

    Has anyone else had issues in loading frameworks?  As a workaround,
    I'm going to just create a single image framework that will be shared
    amongst all my projects.  Whether or not its one framework or many, my
    images need to all have unique names, so I won't have any issues
    putting them all into a single framework.

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • On Dec 29, 2007, at 8:30 AM, Ricky Sharp wrote:

    > I'm being floored by an issue where NSBundle's bundleWithIdentifier:
    > is failing to load one of my frameworks.
    >

    There's the problem.  bundleWithIdentifier doesn't load frameworks:

    > Returns the previously created NSBundle instance that has a given
    > bundle identifier

    So the framework need to be loaded implicitly (via dyld's app
    launching process) or explicitly (by using NSBundle's bundleWithPath:)

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium | prime : build, mutate, evolve, animate : the next
    generation of fractal art
  • > I'm being floored by an issue where NSBundle's bundleWithIdentifier:
    > is failing to load one of my frameworks.

    NSBundles' bundleWithIdentifier: method won't load the bundle you are
    requesting, it will simply return an already initialized framework
    matching the identifier. If you want to get the image using this
    method you need to load the framework before attempting to use its
    resources. This can be done by simply linking against the framework.

    - Keith
  • On Dec 29, 2007, at 9:12 AM, glenn andreas wrote:

    >
    > On Dec 29, 2007, at 8:30 AM, Ricky Sharp wrote:
    >
    >> I'm being floored by an issue where NSBundle's
    >> bundleWithIdentifier: is failing to load one of my frameworks.
    >>
    >
    > There's the problem.  bundleWithIdentifier doesn't load frameworks:
    >
    >> Returns the previously created NSBundle instance that has a given
    >> bundle identifier
    >
    >
    > So the framework need to be loaded implicitly (via dyld's app
    > launching process) or explicitly (by using NSBundle's bundleWithPath:)

    Thanks for this info; all is now well.

    I also found the reason why the first call to bundleWithIdentifier:
    was working.  It was that, for whatever reason, the first images
    framework was being loaded.  Perhaps it's Xcode that loaded it.  But
    strange that the sister project that built the second images framework
    kept the framework unloaded.  None of my apps or Plug-Ins link to this
    framework; it's just a common storage location for images.

    Anyhow, I'm now explicitly accessing the frameworks via
    bundleWithPath:  And, because all I'm accessing is image resources, I
    need not load the framework.

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
  • On Dec 29, 2007, at 9:40 AM, Keith Duncan wrote:

    >> I'm being floored by an issue where NSBundle's
    >> bundleWithIdentifier: is failing to load one of my frameworks.
    >
    > NSBundles' bundleWithIdentifier: method won't load the bundle you
    > are requesting, it will simply return an already initialized
    > framework matching the identifier. If you want to get the image
    > using this method you need to load the framework before attempting
    > to use its resources. This can be done by simply linking against the
    > framework.

    The first statement here is correct; that's the behavior I was
    seeing.  However, as I stated in my reply to Glenn, you need not load
    the framework if all you're accessing is resources (see docs on
    NSBundle's load)

    Also, I'm able to dynamically find my image frameworks without the
    need of explicitly linking.  This allows me to drop in new frameworks
    without the need of rebuilding the various IB Plug-Ins I now have.

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
previous month december 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