gpt4 book ai didi

objective-c - NSMutableArray addObject 不影响计数?

转载 作者:行者123 更新时间:2023-12-01 16:52:56 28 4
gpt4 key购买 nike

谁能告诉我为什么 logging [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];
}
}

最佳答案

“礼物”是否已初始化?如果为 nil,[giftees count] 也将返回 0

关于objective-c - NSMutableArray addObject 不影响计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14225800/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com