Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Friend classes in Objective-C

Tags:

objective-c

Is there any way to create something like friend classes in Objective-C?

like image 361
Casebash Avatar asked Feb 11 '10 00:02

Casebash


1 Answers

First declare a "private property" using the standard class extension method:

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

Then recreate the properties in a category:

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

This interface is only accessible to those who import VisualNotePlayer+Views.h

like image 119
Casebash Avatar answered Nov 16 '22 02:11

Casebash