gpt4 book ai didi

iphone - 类扩展和框架

转载 作者:技术小花猫 更新时间:2023-10-29 11:02:26 26 4
gpt4 key购买 nike

我开发了自己的框架,其中包含我经常在我的应用程序中使用的有用类/方法。最近,我为 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 suis une chaîne avec des caractères spéciaux2012-01-31 17:01:09.924 TestCUtils[4782:207] -[__NSCFConstantString removeDiacritics]:无法识别的选择器发送到实例 0x340c

但是如果我直接在应用程序中添加我的类扩展(在我的框架之外),它工作正常...

有什么提示吗?

** 编辑 **

正如你们中的一些人所问,我在“其他链接器标志”中添加了 -all_load 和 -ObjC 选项,但问题仍然存在。

enter image description here

最佳答案

看看这个technical Q&A这解释了@Ell Neal 提到的 -ObjC 和 -all_load 选项。

注意 需要在链接框架的项目(即框架的客户端)上设置链接器选项,而不是框架本身。从您的屏幕截图看来,您正在为您的框架项目设置选项,因为我可以在左侧看到源文件 NString+Extensions.m

关于iphone - 类扩展和框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9082833/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com