我开发了自己的框架,其中包含我经常在我的应用程序中使用的有用类/方法。最近,我为NSString“NSString + Extensions.h/m”添加了一个类扩展来添加我自己的方法。例如:类扩展和框架
- 的NSString + Extensions.h
@interface NSString (Extensions) - (NSString *)removeDiacritics; @end
- 的NSString + Extensions.m
#import "NSString+Extensions.h" @implementation NSString (Extensions) - (NSString *)removeDiacritics { return [[[NSString alloc] initWithData:[self dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] encoding:NSASCIIStringEncoding] autorelease]; } @end
我成功地编译了我的框架。但是,当我尝试使用这个类扩展的功能之一在任何应用程序:
- AppDelegate.m
// CUtils is the name of the framework. CUtils.h contains #import of all header files // contained in my framework #import <CUtils/CUtils.h> @implementation AppDelegate ... - (void)applicationDidBecomeActive:(UIApplication *)application { /* Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previouslyin the background, optionally refresh the user interface. */ NSString *toto = @"Je suis une chaîne avec des caractères spéciaux"; NSLog(@"%@", toto); NSLog(@"%@", [toto removeDiacritics]); }
...
我得到的以下错误:
2012-01-31 17:01:09.921 TestCUtils [4782:207] Je猪链球菌UNE CHAINE AVEC DES CARACTERESspéciaux012012-01-31 17:01:09.924 TestCUtils [4782:207] - [__ NSCFConstantString removeDiacritics]:无法识别选择
但如果添加我的类扩展直接发送到实例0x340c在应用程序(我的框架之外),它工作正常...
任何提示?
**编辑**
你们有些人问,我已经添加-all_load和“其它链接器标记” -ObjC选项,但问题依然存在。
太棒了!有用。我在应用程序目标中只添加了-ObjC链接器标志,并且正在工作。但我有个问题。在我的框架中,我创建了一个类来管理SQLite数据库,所以我需要链接libsqlite3.dylib。当我使用这个新的链接器标志将我的框架添加到我的应用程序中时,由于我没有链接libsqlite3.dylib,因此我有编译错误,即使我已经将其链接到了我的框架中(不知道我是否清楚足够)。也许我失去了一些东西...... – Niko 2012-02-01 08:51:09
这可能是一个单独的问题。一般来说,您将需要显式链接应用程序中的相关库。如果链接一个自定义框架也会引入依赖库,那将会很好,但我认为没有办法做到这一点。 – 2012-02-01 08:58:25