views:

484

answers:

3

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 {
    @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

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!

+1  A: 

Since the base class is the one with the _delegate iVar, why do you not have the property defined in the TCPEndpoint base class? Properties are just methods that get inherited like any other...

Kendall Helmstetter Gelner
+1  A: 

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):

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

@property (assign) id<TCPConnectionDelegate> delegate;

@end

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

...
@end

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.

Dave DeLong
Ah, yes! Dave, your post was very helpful. Pulling the delegates down a level fixes this problem and I believe newer revisions of the BLIP / MYNetwork project will include this change. Thanks!
Buffalo
Glad you liked it. Feel free to vote it up. =)
Dave DeLong
A: 

hi, the real question should be why can't I use superclass's ival in synthesize

-1 Ask a new question instead of hijacking a 10 month old question.
Dave DeLong