我在XCode中收到了上述編譯器錯誤,我無法弄清楚發生了什麼。從不兼容的指針類型傳遞'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;
在ApplicationDelegate.m
我正在錯誤 「傳遞從兼容的指針類型 'obj_setProperty' 的參數4」。我做了一些研究,發現'保留'只適用於班級類型,這很公平。如果我實際上刪除了「保留」行
@property (nonatomic, retain) id<ServerDateTimeUpdating> *serverDateTimeDelegate;
它確實編譯沒有投訴。但是,我認爲,這是錯誤的做法。當然我的'身份證'是一類的類型,當然它應該被保留在二傳手。順便說一句,這是我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;
最後一行導致「傳遞從兼容的指針類型‘setServerDateTimeDelegate’的參數1」的的XCode錯誤消息。
非常感謝!這確實解決了我的問題。 – McKrassy 2011-01-19 00:01:45