2010-02-11 6 views
18

Objective-C에서 friend 클래스와 같은 것을 만들 수있는 방법이 있습니까?Objective-C의 친구 클래스

// VisualNotePlayer+Views.h 
@interface VisualNotePlayer(Views) 
@property (nonatomic, retain) UIView *currentView; 
@end 

이 인터페이스는 VisualNotePlayer+Views.h를 가져 사람들 만 액세스 할 수 있습니다 :

// VisualNotePlayer.h 
@interface VisualNotePlayer : NSObject<NotePlayer>{ 
    @private 
    UIView *_currentView; 
} 

// VisualNotePlayer.m 
@interface VisualNotePlayer() 
@property (nonatomic, retain) UIView *currentView; 
@end 

@implementation VisualNotePlayer 
@synthesize currentView=_currentView; 
... 
@end 

그런 다음 범주의 속성을 다시 :

답변

30

첫 번째는 "개인 재산"표준 클래스 확장 방법을 사용하여 선언

+0

아 ... 그래서 동일한 클래스에 대해 여러 개의 .h 파일을 효과적으로 가져야합니다. –

5

ObjC에는 친구 클래스와 같은 것이 없습니다.

다른 클래스의 개인 변수에 액세스하기 위해 친구로 선언 할 필요조차 없습니다. 예를 들어, 컴파일러 검사를 거치지 the_object->_ivar_name를 얻기 위해 런타임 기능

id the_private_ivar; 
object_getInstanceVariable(the_object, "_ivar_name", &the_private_ivar); 

를 사용할 수 있습니다.