Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 将数组计数分配给int、NSNumber或整数失败_Objective C_Nsarray - Fatal编程技术网

Objective c 将数组计数分配给int、NSNumber或整数失败

Objective c 将数组计数分配给int、NSNumber或整数失败,objective-c,nsarray,Objective C,Nsarray,将int、NSNumber和nsInteger分配给数组计数失败 这是我的代码行 int diamondCount = [diamonds count]; 钻石在哪里是一个障碍 我开发了这个应用程序,它在那条线上抛出了一个EXC_BAD_访问权限 所以我查看了NSArray count方法,发现它返回一个整数 所以我做了: NSUInteger diamondCount = [diamonds count]; 这仍然让我无法访问EXC_BAD_,所以在最后一次尝试时,我将其分配

将int、NSNumber和nsInteger分配给数组计数失败

这是我的代码行

 int diamondCount = [diamonds count];
钻石在哪里是一个障碍

我开发了这个应用程序,它在那条线上抛出了一个EXC_BAD_访问权限

所以我查看了NSArray count方法,发现它返回一个整数

所以我做了:

     NSUInteger diamondCount = [diamonds count]; 
这仍然让我无法访问EXC_BAD_,所以在最后一次尝试时,我将其分配给了一个编号为Withinteger的nsnumber:


它还是死机了。。。。有什么想法吗?

钻石
并没有指向真正的(有效的)NSArray。检查其初始化。

菱形
不指向真实(且有效)的NSArray。检查其初始化。

尝试以下操作:

NSArray *myArray;
NSDate *aDate = [NSDate distantFuture];
NSValue *aValue = [NSNumber numberWithInt:5];
NSString *aString = @"a string";

myArray = [NSArray arrayWithObjects:aDate, aValue, aString, nil];
int i = [myArray count];
NSLog(@"%d",i);
NSInteger j = [myArray count];
NSLog(@"%d",j);
NSNumber *k = [myArray count];
NSLog(@"%d",k);
/*output
2011-11-21 17:01:48.272 test[48840:1303] 3
2011-11-21 17:01:48.272 test[48840:1303] 3
2011-11-21 17:01:48.273 test[48840:1303] 3*/
试试这个:

NSArray *myArray;
NSDate *aDate = [NSDate distantFuture];
NSValue *aValue = [NSNumber numberWithInt:5];
NSString *aString = @"a string";

myArray = [NSArray arrayWithObjects:aDate, aValue, aString, nil];
int i = [myArray count];
NSLog(@"%d",i);
NSInteger j = [myArray count];
NSLog(@"%d",j);
NSNumber *k = [myArray count];
NSLog(@"%d",k);
/*output
2011-11-21 17:01:48.272 test[48840:1303] 3
2011-11-21 17:01:48.272 test[48840:1303] 3
2011-11-21 17:01:48.273 test[48840:1303] 3*/

这并不能真正回答问题。这是一个很有趣的练习,你可以这样做,但这并不能真正回答问题。不过,这是一个有趣的练习,你可以这样展示它。