2011-01-18 16 views
0

から渡しています。上記のコンパイラエラーがXCodeで発生していますが、何が起こっているのか分かりません。 ApplicationDelegate.mで'obj_setProperty'の引数4を互換性のないポインタ型

#import <UIKit/UIKit.h> 

// #import "HeaderPanelViewController.h" 
#import "HTTPClientCommunicator.h" 
#import "WebSocket.h" 

@class HeaderPanelViewController; 

@protocol ServerDateTimeUpdating 
-(void)serverDateTimeHasBeenUpdatedWithDate:(NSString *) dateString andTime:(NSString *) timeString; 
@end 

@interface SmartWardPTAppDelegate : NSObject <UIApplicationDelegate, WebSocketDelegate> { 

} 

@property (nonatomic, retain) id<ServerDateTimeUpdating> *serverDateTimeDelegate; 
.... 
@end 

そして、この行の

@synthesize serverDateTimeDelegate; 

私は、 "互換性のないポインタ型から 'obj_setProperty' の引数を渡す4" エラーを取得しています。私は少しの研究を行い、「保持する」ことはクラスの型だけで十分であることを発見しました。私が実際にラインから「保持」を削除した場合

@property (nonatomic, retain) id<ServerDateTimeUpdating> *serverDateTimeDelegate; 

苦情なしでコンパイルします。しかし、私はそれが間違っていると思います。確かに私の 'id' はクラスタイプでであり、確かにでなければなりません。ところで、ここで前述のプロトコルを実装して、私のHeaderPanelViewControllerの宣言は次のとおりです。

また
@interface HeaderPanelViewController : UIViewController<ServerDateTimeUpdating> { 

} 

... 
@end 

、私は実際に私は実際に私を登録するにはセッターを呼び出すとき、私は後でトラックダウン問題を取得保持を削除しない場合デリゲートとしてHeaderPanelViewController:

// Register this instance as the delegate for ServerDateTimeUpdating 
// Retrieve the ApplicationDelegate... 
ApplicationDelegate *applicationDelegate = (ApplicationDelegate *) [UIApplication sharedApplication].delegate; 
// ...and register this instance 
applicationDelegate.serverDateTimeDelegate = self; 

最後の行は、XCodeのエラーメッセージ「互換性のないポインタ型から 『setServerDateTimeDelegate』の引数1を渡す」の原因となります。

答えて

6

あなたの問題は、プロパティ宣言である:つまり、

typedef struct objc_object { 
    Class isa; 
} *id; 

id次のとおりです。あなたがクリックして "ID" ダブルを指揮した場合、あなたはそれのように定義されて表示されます

@property (nonatomic, retain) id<ServerDateTimeUpdating> *serverDateTimeDelegate; 

既にオブジェクト参照。したがって、serverDateTimeDelegateの直前の*は不要で間違っています。そこにオブジェクト参照へのポインタがあるのは、オブジェクト参照だけが必要なときです。

6

あなたの問題はここにある:あなたがポインタ(*)としてserverDateTimeDelegateを宣言するよう

@property (nonatomic, retain) id<ServerDateTimeUpdating> *serverDateTimeDelegate; 

idを効果的財産のポインタへのポインタを行い、既にポインタ型です。

*を取り除いても問題ありません。

+0

ありがとうございました!それは確かに私の問題を解決しました。 – McKrassy

+0

@McKrassy大歓迎です! :-) –

関連する問題