NSMutableArray addObject 不影响计数? [英] NSMutableArray addObject not affecting count?

查看:33
本文介绍了NSMutableArray addObject 不影响计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我为什么记录 [self.giftees count] 会一直返回 0,即使我正在向它添加对象?

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

标题:

#import <UIKit/UIKit.h>

@interface Test2AppDelegate : NSObject <UIApplicationDelegate>  
{
    UIWindow *window;
    NSMutableArray *giftees;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) NSMutableArray *giftees;

@end

从 didFinishLaunchingWithOptions 调用:

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];
}
}

推荐答案

giftees"是否已初始化?如果为 nil,[giftees count] 也会返回 0

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

这篇关于NSMutableArray addObject 不影响计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆