NSMutableArray addObject不影响计数吗? [英] NSMutableArray addObject not affecting count?
本文介绍了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"是否已初始化?如果为零,则[giftees count]也将返回0
Is "giftees" initialized? If it is nil, [giftees count] will return 0 as well
这篇关于NSMutableArray addObject不影响计数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文