开发者

XCode 4 : error at runtime "unrecognized selector sent to instance"

I develop a static lib开发者_开发知识库rary and build my lib.a.

When I use this library in a iOS project (iPhone app built with -ObjC and -all_load flags for linker), I get this error at runtime :

unrecognized selector sent to instance

This error occurs when I try to call a class method.

+ (MyObject *) GetSingleton;

For information, I don't get error when I call an instance method.

- (void) Log;

Have you got an idea of the problem ?


When you create your singleton, try this:

+ (MyObject *)GetSingleton {
    static MyObject* singletonInstance; 

    @synchronized(self) {
        if (!singletonInstance)
            singletonInstance = [[MyObject alloc] init]; 
    }

    return singletonInstance;
}

Hope that helps.


Hum, I fixed the problem re-creating my project !

I don't know why, my project made bad linking for class method, and not for instance method.

Now, with new project and linkg to my static library, all is OK at runtime.

Maybe it was a problem because of multiples static libraries I built, with probably a bad cache or dependencies...

Thanks for your answers developers !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜