嗨,我刚刚学习了目标C,我正在做一些练习来练习自己。我在这里有两个班,一个是“主班”,一个“副班”。我需要的是获取我的“主类”的所有实例,并将其放入一个数组中。我还想在我的“子类”中使用它。下面我举一个小例子。
@interface mainClass : NSObject
static NSArray *instanceObj;
@end
@implementation mainClass
//Here i used the designated initializer to initialize and add the instance to the Array
@end
@interface subClass:mainClass
@end
@implementation subClass
//Here i want to use the Array to get instances of mainClass.
@end
如果我像上面的例子那样做,我会得到一个警告,说明没有使用静态数组,并且当从数组中获取数据时,它为nil。我还尝试在“main Class”的实现文件中声明静态数组,但我不能在“Sub Class”中使用数组。请给我一个解决方案。
朋友们,虽然这个问题没有那么重要,但它可能会帮助我理解一些事情。所以请帮我理解这个概念,我可以完全删除这个问题。非常感谢。