Accessing variables of another class in xcode

前端 未结 5 413
一向
一向 2021-01-24 11:52

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

I want to access some variables I set in balloon.h

5条回答
  •  梦毁少年i
    2021-01-24 12:49

    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 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.

提交回复
热议问题