views:

142

answers:

2

My Question is similar to This SO question, but with the main difference being that I'm using class methods. Some code:

OpenFeint+private.h

@interface OpenFeint (Private)
// ...
+ (void) createSharedInstance;

OpenFeint+private.mm

+ (void) createSharedInstance
{
   //...
}

OpenFeint.mm

+ (void) initializeWithProductKey:(NSString*)productKey 
       andSecret:(NSString*)productSecret 
       andDisplayName:(NSString*)displayName
       andSettings:(NSDictionary*)settings 
       andDelegates:(OFDelegatesContainer*)delegatesContainer
{
    [OpenFeint createSharedInstance];
    // ...

MyApp.mm:

// ...
#import "OpenFeint.h"
// ...
[OpenFeint initializeWithProductKey: OF_PRODUCT_KEY 
        andSecret: OF_PRODUCT_SECRET
        andDisplayName: OF_DISPLAY_NAME
        andSettings: openFeintSettings
        andDelegates: [OFDelegatesContainer containerWithOpenFeintDelegate: self]];

And the error is:

2010-07-22 11:30:15.239 MyApp[20210:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[OpenFeint createSharedInstance]: unrecognized selector sent to class 0x1cdb1c'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x02d6f919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x02ebd5de objc_exception_throw + 47
    2   CoreFoundation                      0x02d714eb +[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x02ce1116 ___forwarding___ + 966
    4   CoreFoundation                      0x02ce0cd2 _CF_forwarding_prep_0 + 50
    5   MyApp                               0x0002844d +[OpenFeint initializeWithProductKey:andSecret:andDisplayName:andSettings:andDelegates:] + 48
        // ...

Everything compiles & links just fine, but I'm getting this goofy error.

One last thing -- All the OpenFeint stuff is is a static library and, yes, it compiled & linked as well. This is my first static library so I'm likely just missing some important step. Any clues?

Thanks!

+1  A: 

Hmmm, I seem to have found a workaround, but I'm not sure if it's a correct fix. I added the linker flag -all_load (in addition to -ObjC), and all seems to work, now.

Question revision/addition: is this a "legit" fix? Is there a better one?

Olie
Yes. That is the legit fix. You have to do that if you want to load in everything from a static library.
Matt Long
+1  A: 

OpenFeint+private is a category so if you don't import the OpenFeint+private.h file everywhere you call it, you will get the selector not recognized error every time you call it. It's as if you never defined the method at all.

TechZen