我正在尝试创建一个 NSMutableArray
,其中包含给定索引处另一个的内容。
如果前一个数组在索引处有任何内容,我将使用 initWithArray:
初始化新数组,否则使用普通的 init
此代码不起作用,但您应该能够从中得到想法:
NSMutableArray *typeCourseCutId;
if([self.typeCourseCut objectAtIndex:typeCourseIndex] != nil){
typeCourseCutId = [[NSMutableArray alloc]initWithArray:[self.typeCourseCut objectAtIndex:typeCourseIndex]];
} else {
typeCourseCutId = [[NSMutableArray alloc]init];
}
这种测试有解决方案吗?
最佳答案
有一个特殊的类叫做NSNull
这是专门为在集合中用作空指示器而创建的:
The
NSNull
class defines a singleton object used to representnull
values in collection objects (which don’t allownil
values).
if([self.typeCourseCut objectAtIndex:typeCourseIndex] != [NSNull null]) ...
关于objective-c - 测试我的数组在给定索引处是否为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12098271/