2009-07-09 64 views
0

我正在使用BLIP/MYNetwork库建立iPhone和我的电脑之间的基本tcp套接字连接。到目前为止,代码生成和模拟器正常运行,但部署到设备产生以下错误:iPhone上的伊娃继承问题

error: property 'delegate' attempting to use ivar '_delegate' declared in super class of '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”的公共属性?感谢您的帮助!

回答

2

它看起来像TCPEndpoint有一个私人实例变量称为“委托”,并且由于它是私人的,这个子类无法访问它。

如果需要TCPConnection到有明显的委托对象,那么我推荐以下(剪切多余的东西):

//TCPConnection.h 
@interface TCPConnection : TCPEndpoint { 
    id<TCPConnectionDelegate> _connectionDelegate; 
} 

@property (assign) id<TCPConnectionDelegate> delegate; 

@end 

//TCPConnection.m 
@implementation TCPConnection 
@synthesize delegate=_connectionDelegate; 

... 
@end 

基本上,属性语法允许有一个合成属性对应于实例变量与属性名称不同,使用simple =运算符。

+0

啊,是的!戴夫,你的帖子非常有帮助。将代表降到一个级别可以解决这个问题,我相信BLIP/MYNetwork项目的更新版本将包含此更改。谢谢! – Buffalo 2009-07-09 22:11:45

1

由于基类是带有_delegate iVar的基类,为什么您没有在TCPEndpoint基类中定义的属性?属性只是像任何其他继承的方法...