谁能告诉我为什么即使我向其中添加对象,日志记录[self.giftees count]仍返回0?
标头:
#import <UIKit/UIKit.h>
@interface Test2AppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
NSMutableArray *giftees;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) NSMutableArray *giftees;
@end
从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];
}
}
最佳答案
是否已初始化“giftee”?如果为零,则[giftees count]也将返回0