在xcode中访问另一个类的变量 [英] Accessing variables of another class in xcode

查看:126
本文介绍了在xcode中访问另一个类的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 balloonGameViewController.h 和我做的另一个名为 balloon.h的课程

I have a balloonGameViewController.h and another class I made called balloon.h

我想从 viewController 访问我在 balloon.h 中设置的一些变量

I want to access some variables I set in balloon.h from the viewController

我有什么方法可以达到这个目的吗?

Is there any way I can achieve this?

推荐答案

你的变量是否在ballon.h中设置?您应该使用@property来声明您希望其他类能够访问的变量。然后,您可以通过将它们视为方法或点符号来访问它们:

How are your variables set in ballon.h? You should use @property to declare variables that you want other classes to be able to access. Then, you can access them either by treating them as a method, or dot notation:

myObject.variable;

myObject应该是balloon类型的实例,可以通过导入balloon.h并初始化来创建一个新实例,如果你还没有实例。

myObject should be an instance of type balloon, which can be created by importing the balloon.h and initializing a new instance, if you do not already have one.

这篇关于在xcode中访问另一个类的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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