我在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