如何访问成员对象
我创建了一个名为 Students 的自定义对象,它有两个 nsstring 对象。一个是姓名,另一个是学生证。如果我尝试将自定义对象传递给需要 nsstring 的对象,则它不起作用。我想把名字传过去我该怎么做?
I have made a custom object called students that has two nsstring object. One is for the name and the other for the student id. If I try to pass the custom object to something that takes nsstring, it doesn't work. I want to pass the name. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样嵌套方法调用:
或者,如果您将成员定义为属性并希望通过点表示法访问它们:
点表示法的唯一问题是编译器很可能会给出您警告它找不到属性
name
,因此您需要在通过点表示法访问属性之前将其转换为适当的数据类型。You can nest your method calls like this:
Or if you defined your members as properties and want to access them via dot-notation:
The only issue with the dot-notation approach is the compiler will most likely give you warning that it couldn't find the property
name
, so you will need to cast it to the appropriate data type before accessing the property via dot-notation.