2009-07-09 3 views
0

BLIP/MYNetwork 라이브러리를 사용하여 iPhone과 내 컴퓨터 간의 기본 TCP 소켓 연결을 설정하고 있습니다. 지금까지 코드 빌드 및 시뮬레이터에서 제대로 실행되지만 장치에 배포하면 다음과 같은 오류 산출 :iPhone에서 ivar 상속 문제

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에는 "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 = 연산자를 사용하여 속성과 이름이 같은 인스턴스 변수.

+0

아, 그래! Dave, 귀하의 게시물은 매우 유용했습니다. 델리게이트를 한 수준 아래로 끌어 내리면이 문제가 해결되며 BLIP/MYNetwork 프로젝트의 최신 개정판에 이러한 변경 사항이 포함될 것입니다. 감사! – Buffalo

+0

다행히 좋았어. 기꺼이 투표하십시오. =) –

1

기본 클래스는 _delegate iVar가있는 클래스이므로 TCPEndpoint 기본 클래스에 정의 된 속성을 사용하지 않는 이유는 무엇입니까? 속성은 다른 어떤 것처럼 상속 된 메소드 일뿐입니다 ...