I'm trying to create an NSMutableArray containing the contents of another at a given index.
I'm initializing the new array with initWithArray: if the previous array has anything at the index, otherwise with plain init
This code doesn't work but you should be able to get the idea from it:
NSMutableArray *typeCourseCutId;
if([self.typeCourseCut objectAtIndex:typeCourseIndex] != nil){
typeCourseCutId = [[NSMutableArray alloc]initWithArray:[self.typeCourseCut objectAtIndex:typeCourseIndex]];
} else {
typeCourseCutId = [[NSMutableArray alloc]init];
}
Is there a solution for this kind of test?
objectAtIndex:will never returnnilfor any index. Cocoa arrays can't containnil, and if you try to access an index outside the array's bounds, an exception will be raised. Trying to putnilinto an array will also cause an exception.