使用以下代码我总是得到category.subCategories计数使用Xcode调试儿童阵列总是空
Category *category = [[Category alloc] init];
category.title = @"Pubs & Bars";
category.icon = @"cat_pubs&bars";
category.subCategories == [[NSMutableArray alloc] init];
Category *subCategory = [[Category alloc] init];
subCategory.title = @"Test Sub Category 1";
[category.subCategories addObject:subCategory];
为0
使用以下代码中定义的对象:
@interface Category : NSObject {
NSInteger *categoryId;
NSMutableString *title;
NSString *icon;
NSMutableArray *subCategories;
}
@property(assign,nonatomic,readonly) NSInteger *categoryId;
@property(nonatomic,copy) NSMutableString *title;
@property(nonatomic,copy) NSString *icon;
@property(nonatomic,retain) NSMutableArray *subCategories;
@end
您的代码会泄漏内存 - 您需要释放分配给subCategories和subCategory本身的数组,因为您增加了它们的保留计数。 – Vladimir 2010-01-26 12:23:27
谢谢,但这只是一个原型,实际的代码将从SQLite读取数据 – 2010-01-26 13:54:13
为什么不使用Core Data? – bbum 2010-01-26 16:56:34