【发布时间】:2012-06-06 00:08:35
【问题描述】:
我收到以下警告:“将保留的对象分配给不安全的属性;分配后对象将被释放”用于以下代码的 sn-p。有人可以帮我解决这个问题吗?我设置 detailViewController.restaurantsSortedByDistance 的第二行是警告突出显示的部分.....
** RestaurantList.h **
@property (nonatomic) NSMutableArray *restaurantsSortedByDistance;
** end **
RestaurantList *detailViewController = [[RestaurantList alloc] initWithNibName:@"RestaurantList" bundle:nil];
detailViewController.restaurantsSortedByDistance = [[NSMutableArray alloc] initWithArray:[self returnRestaurantsSortedByDistance:rows]];
【问题讨论】:
-
你是如何声明餐馆SortedByDistance的?您很可能希望它成为(保留)属性,但实际上它是(分配)属性。
-
我也遇到过这个问题。转换工具正在做正确的事情。这是错误的编译器警告。 ARC下的默认值实际上是“strong”,而不是“assign”。 (assign 是手动引用计数模式下的默认值)。如果您不理会您的代码,您会发现它实际上可以正常工作。
标签: objective-c ios xcode automatic-ref-counting