2012年4月13日金曜日

property 'someProperty' requires method 'someProperty' to be defined


... warning: property '...' requires method '...' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation @implementation MYAppDelegate

@interfaceで@propertyを宣言したが、それに対応するメソッドが見つからない場合に発生します。

対処:
(1)@synthesizeで合成する。
(2)@synthesizeを使わない場合は命名規則に沿ってメソッドを実装する。

例1:
LocationsサンプルのpersistentStoreCoordinatorに関する部分。
persistentStoreCoordinatorをreadonlyとするため、@propertyで宣言したものと同名のインスタンス変数、メソッドを追加する。
readonlyなのでgetterメソッドのみ追加されている。このgetterメソッドがないとこのエラーが発生する。

@interface LocationsAppDelegate : NSObject <UIApplicationDelegate> {
    NSPersistentStoreCoordinator *persistentStoreCoordinator;
}
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@end

@implementation LocationsAppDelegate
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
   ....
   return persistentStoreCoordinator;
}
@end

0 件のコメント: