Objective-c – Inheritance issue with ivar on the iPhone


I am using the BLIP/MYNetwork library to establish a basic tcp socket connection between the iPhone and my computer. So far, the code builds and runs correctly in simulator but deploying to device yields the following error:

error: property 'delegate' attempting
to use ivar '_delegate' declared in
super class of 'TCPConnection'

@interface TCPConnection : TCPEndpoint {
    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> 

/** 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; 

    @interface TCPEndpoint : NSObject {
        NSMutableDictionary *_sslProperties;
        id _delegate; 
    - (void) tellDelegate: (SEL)selector withObject: (id)param;

Does anyone know how I would fix this? Would I simply declare _delegate as a public property of the base class "TCPEndPoint"? Thanks for the help ya'll!

Best Solution

It looks like TCPEndpoint has a private instance variable called "delegate", and since it's private, this subclass can't access it.

If you need TCPConnection to have a distinct delegate object, then I would recommend the following (cutting out unnecessary stuff):

@interface TCPConnection : TCPEndpoint {
  id<TCPConnectionDelegate> _connectionDelegate;

@property (assign) id<TCPConnectionDelegate> delegate;


@implementation TCPConnection
@synthesize delegate=_connectionDelegate;


Basically, the properties syntax allows you to have a synthesized property correspond to an instance variable that does not have the same name as the property, using the simple = operator.