我正在使用BLIP / MYNetwork库在iPhone和我的电脑之间建立基本的tcp套接字连接。到目前为止,代码在模拟器中构建和运行正确,但部署到设备会产生以下错误:
错误:属性'委托'尝试 使用ivar'_delegate'声明 超级'TCPConnection'
@interface TCPConnection : TCPEndpoint {
@private
TCPListener *_server;
IPAddress *_address;
BOOL _isIncoming, _checkedPeerCert;
TCPConnectionStatus _status;
TCPReader *_reader;
TCPWriter *_writer;
NSError *_error;
NSTimeInterval _openTimeout; }
/** The delegate object that will be called when the connection opens, closes or receives messages. */
@property (assign) id<TCPConnectionDelegate> delegate;
/** The delegate messages sent by TCPConnection. All methods are optional. */
@protocol TCPConnectionDelegate <NSObject>
@optional
/** Called after the connection successfully opens. */
- (void) connectionDidOpen: (TCPConnection*)connection;
/** Called after the connection fails to open due to an error. */
- (void) connection: (TCPConnection*)connection failedToOpen: (NSError*)error;
/** Called when the identity of the peer is known, if using an SSL connection and the SSL
settings say to check the peer's certificate.
This happens, if at all, after the -connectionDidOpen: call. */
- (BOOL) connection: (TCPConnection*)connection authorizeSSLPeer: (SecCertificateRef)peerCert;
/** Called after the connection closes. You can check the connection's error property to see if it was normal or abnormal. */
- (void) connectionDidClose: (TCPConnection*)connection;
@end
@interface TCPEndpoint : NSObject {
NSMutableDictionary *_sslProperties;
id _delegate;
}
- (void) tellDelegate: (SEL)selector withObject: (id)param;
@end
有谁知道我会如何解决这个问题?我是否只是将_delegate声明为基类“TCPEndPoint”的公共属性?谢谢你的帮助!
答案 0 :(得分:2)
看起来TCPEndpoint有一个名为“delegate”的私有实例变量,由于它是私有的,因此该子类无法访问它。
如果你需要TCPConnection来拥有一个独特的委托对象,那么我会推荐以下内容(删除不必要的东西):
//TCPConnection.h
@interface TCPConnection : TCPEndpoint {
id<TCPConnectionDelegate> _connectionDelegate;
}
@property (assign) id<TCPConnectionDelegate> delegate;
@end
//TCPConnection.m
@implementation TCPConnection
@synthesize delegate=_connectionDelegate;
...
@end
基本上,属性语法允许您使用simple =运算符使合成属性对应于与属性名称不同的实例变量。
答案 1 :(得分:1)
由于基类是带有_delegate iVar的基类,为什么不在TCPEndpoint基类中定义属性?属性只是像任何其他方式一样继承的方法......