NSMutableArray addObject does not affect the score?

Can someone tell me why logging [self.giftees count] keeps returning 0 even though I am adding objects to it?

Title:

#import <UIKit/UIKit.h> @interface Test2AppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; NSMutableArray *giftees; } @property (nonatomic, retain) UIWindow *window; @property (nonatomic, retain) NSMutableArray *giftees; @end 

Called from didFinishLaunchingWithOptions:

 - (void)bootstrapGiftees { NSArray *gifteeNames = [NSArray arrayWithObjects:@"Jesse",,nil]; for (NSString *gifteeName in gifteeNames) { GifteeModel *g = [[GifteeModel alloc] init]; g.name = gifteeName; [self.giftees addObject:g]; NSLog(@"giftees count = %d", [self.giftees count]); [g release]; } } 
0
source share
2 answers

Is "giftees" initialized? If it is zero, [giftees count] will also return 0

+6
source

Since you most likely never initialized the giftees array at all, so that it is still zero when this code works.

+2
source

Source: https://habr.com/ru/post/1400896/


All Articles