When you are calling a member function defined in a class category (https://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/chapters/occategories.html) from a different static library, you might see a run-time exception of "selector not recognized".
This is a well-know issue with Xcode and iOS. There is a technical note from Apple to describe the problem and the workaround by using the -all_load flag or the -force_load flag followed by the archive path:
https://developer.apple.com/library/mac/#qa/qa1490/_index.html
There is also another workaround without defining the flag. In the file that define the class category, add a C function to the .h and .m, and call this function anywhere in the project that you call the member function of the class category. For example, if you have a class category called UIImage (A) in UIImage+A.h and UIImage+A.m, you can add a function like this:
UIImage+A.h
------------------
// This function needs to be called in the file that uses UIImage (A)
void forceLoadUIImageCategoryA(void);
@interface UIImage (A)
...
@end
UIImage+A.m
------------------
void forceLoadUIImageCategoryA(void)
{
// Do nothing
}
@implementation UIImage (A)
...
@end
In the file that uses any member functions of UIImage (A), call forceLoadUIImageCategoryA(); anywhere. Calling this C function will make Xcode link the .h and .m.
Saturday, February 25, 2012
Xcode warning: no previous prototype for function ...
This warning appears when you define a C-style function like this:
In .h:
void foo();
In .m:
void foo()
{
}
However, according to C standard, you should define the function with the void keyword if there is no parameters in your function:
In .h:
void foo(void);
In .m:
void foo(void)
{
}
In .h:
void foo();
In .m:
void foo()
{
}
However, according to C standard, you should define the function with the void keyword if there is no parameters in your function:
In .h:
void foo(void);
In .m:
void foo(void)
{
}
Subscribe to:
Posts (Atom)