Access NSMutableArray from another class - Objective C

前端 未结 5 1816
清歌不尽
清歌不尽 2020-12-22 06:34

I have a main ViewController that contains a desginated class. Within that ViewController there is a Container that is linked to an <

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 06:44

    The basic idea here is that in your original class, the array is referred to by a pointer. Your original class would allocate it and presumably load it. Other parts of your program can be handed the contents of the property, which is a pointer, assign that to their own pointer holder, and use it as if you had declared it there. Please use the above code;

    MyClass *aClass = [[MyClass alloc] initWithMyInitStuff];
    NSMutableArray *ThatArray = aClass.MyArray;
    
    NSLog("Count of ThatArray: %d", [That.Array count]);
    

提交回复
热议问题