Reachability的源代码,在一个静态库中定义,调用的地方在IOS App工程中
Reachability *reach = [[[Reachability alloc] init] autorelease];
reach.key = @"";
xcode调试报错,-[Reachability setKey:]: unrecognized selector sent to instance 0x7fdf949a2cc0
查看Reachability的源代码,确实定义了这个方法
@interface Reachability: NSObject {
@private
NSString *key_;
SCNetworkReachabilityRef reachabilityRef;
}
@property (copy) NSString *key; // Atomic because network operations are asynchronous.
......
在reach.key=@""这行代码打个断点,重新运行查看运行时Reachability的属性
红框中的属

在iOS应用开发中,遇到-[Reachability setKey:]: unrecognized selector sent to instance的错误。问题源于 Reachability 源代码在静态库中定义,但在App工程中调用时出现链接错误。通过调试和使用nm命令检查符号表,发现是静态库与App中存在重复的Reachability定义。解决方法是修改Reachability类名,避免命名冲突。此问题凸显Objective-C缺乏命名空间的缺点,建议代码中使用类名前缀。
4390

被折叠的 条评论
为什么被折叠?



