【发布时间】:2012-08-18 01:49:01
【问题描述】:
以下代码崩溃:
@interface AppDelegate (PrivateMethods)
@property (nonatomic, strong) NSString * name;
@end
@implementation AppDelegate
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.name = @"foobar";
...
错误是:
'-[AppDelegate setName:]: unrecognized selector sent to instance 0x6d73df0'
当我改变时
@interface AppDelegate (PrivateMethods)
到
@interface AppDelegate ()
那没关系,请问是什么原因?
更新:正如下面的回答,因为我必须为此目的使用类扩展,所以现在这个问题变成:使用类扩展来声明私有方法是否可以接受?
例如
@interface AppDelegate ()
- (void) start;
@property (nonatomic, strong) NSString * name;
@end
【问题讨论】:
标签: iphone objective-c ios xcode ipad