Objective-C中的朋友课程 [英] Friend classes in Objective-C

查看:72
本文介绍了Objective-C中的朋友课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在Objective-C中创建类似朋友类的东西吗?

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

推荐答案

首先使用标准的类扩展方法声明私有属性":

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

此界面仅对导入VisualNotePlayer+Views.h

这篇关于Objective-C中的朋友课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆