仅适用于类及其子类的属性 [英] Properties for Class and Its Subclasses Only

查看:78
本文介绍了仅适用于类及其子类的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以定义仅对定义它们的类和该类的子类可用的属性?

Is it possible to define properties that are only available to the class they are defined in, and that class's subclasses?

用另一种方式表示,有没有一种方法来定义受保护的属性?

Stated another way, is there a way to define protected properties?

推荐答案

从技术上讲,没有.属性实际上只是方法,所有方法都是公共的.我们在Objective-C中保护"方法的方法是不让其他人知道它们.

Technically, no. Properties are really just methods, and all methods are public. The way we "protect" methods in Objective-C is by not letting other people know about them.

实际上,是的.您可以在类扩展中定义属性,并仍在主实现块中@synthesize.

Practically, yes. You can define the properties in a class extension, and still @synthesize them in your main implementation block.

这篇关于仅适用于类及其子类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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