Creating an array that contains only objects of a given class

前端 未结 3 1280
一整个雨季
一整个雨季 2021-01-23 15:12

Ok, so I have the code below (Objective-C FYI) and I was wondering if I want to create an NSMutableArray of c_data objects, how would I go about doing that? It\'s s

3条回答
  •  遥遥无期
    2021-01-23 16:08

    [NSMutableArray addObject:[[[c_data alloc] init] autorelease]];
    

    Objective-C arrays aren't typed. It seems you have some C++ unlearning to do.

    On a related note, your inits are pretty bad. You need to call super init as well, as such:

    - (id)init {
      self = [super init];
      if (self != nil) {
        //Initialize here.
      }
      return self;
    }
    

提交回复
热议问题