开发者

NSMutableArray addObject not affecting count?

开发者 https://www.devze.com 2023-01-15 08:32 出处:网络
Can anyone tell me why logging [self.giftees count] keeps returning 0 even though I\'m adding objects to it?

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

header:

#import <UIKit/UIKit.h>

@interface Test2AppDelegate : NSObject <UIApplicati开发者_C百科onDelegate>  
{
    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];
}
}


Is "giftees" initialized? If it is nil, [giftees count] will return 0 as well


Because you most probably never initialized the giftees array at all, so it is still nil when that code runs.

0

精彩评论

暂无评论...
验证码 换一张
取 消