【发布时间】:2011-10-27 13:40:49
【问题描述】:
我有一个单例 (StoreManager) 来帮助我管理我的应用内购买,它有一个名为 productArray 的属性,它的设置如下:
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
self.productArray = response.products;
}
在我商店的视图控制器中,我有以下代码:
-(void)setupPrices
{
if ([[StoreManager sharedStoreManager] productArray]) {
[productArray objectAtIndex:2]...
}
它工作了一段时间,但现在我得到 SIGABRT: index 2 beyond bounds of empty array,所以很明显我的 if 语句已经通过了,即使设置值的方法还没有被调用。我觉得这很奇怪,所以我尝试了一些代码,看起来如果我这样做了
NSArray *array;
NSLog (@"%u", array.count);
我获得了错误的访问权限,如果我这样做了
NSArray *array;
if (array)
NSLog(@"Array is not nil");
语句通过。我确定我在这里遗漏了一些东西。如何检查我的数组是否已设置?
【问题讨论】:
-
观察编译器警告。 @"Array is not nil" 应该使用而不是"Array is not nil"。
标签: objective-c ios cocoa