I am trying to add an object of the same class to a NSMutable array that is defined in the same class. My approach would look like this, but when I tested the array, it was always empty. I also tried adding random Strings or integers.
The .h file:
@property NSMutableArray *anArray;
- (void)addObject: (TheClass*)nameOfObjectToBeAdded;
The .m file:
@synthesize anArray;
- (void)addObject: (TheClass*)nameOfObjectToBeAdded {
[anArray addObject:nameOfObjectToBeAdded];
}
The main.m:
#import "TheClass.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
TheClass *object1 = [[TheClass alloc] init];
TheClass *object2 = [[TheClass alloc] init];
[object1 addObject:object2];
}
return 0;
}
I am trying to add object2 to the NSMutableArray of object1.
Thanks in advance!