如何使财产成为财产 [英] How to make a property of a property

查看:85
本文介绍了如何使财产成为财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太确定如何表达这个问题,因此我将举例说明.我想为一个财产做一个财产.我目前正在使用其他类别的属性:

I'm not quite sure how to word this question, so I'll show examples. I want to make a property for a property. I am currently using a property from a different class:

player = [[Player alloc] init];
player.name = @"PlayerName";

这些属性在Player类中定义,并导入Player.h.

These properties are defined in the Player class, and Player.h is imported.

我想为.name提供一个子属性",所以它看起来像player.name.newProperty. UILabel就是一个例子:

I want to have a 'sub-property' for .name, so it will look like player.name.newProperty. An example of this is for UILabel:

labelName = [[UILabel alloc] init];
self.labelName.text = @"String"; // .text being the 'sub-property'

推荐答案

现在,player.nameNSString

如果您将其设为自定义类(而不是NSString),并具有其自己的属性,则可以将其作为子属性"来访问

If instead of an NSString, you make it a custom class, with it's own properties, you will be able to access them as "sub-properties"

player.name = [[MyCustomObject alloc] init];
player.name.subProperty = @"value";

请记住,您将需要为MyCustomObject创建适当的.m和.h文件并定义其属性.

Keep in mind, you will need to create the appropriate .m and .h files for MyCustomObject and define its properties.

这篇关于如何使财产成为财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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