Здесь есть несколько вопросов.Давайте шаг за шагом пройдемся по существующему коду:
// You are making a new mutable array that has a starting capacity of numberOfStems and assigning it to the referenceArray variable
referenceArray = [NSMutableArray arrayWithCapacity:numberOfStems];
// You then create another new mutable array with the default capacity and re-assign the referenceArray variable. Fortunately, the first array was created with -arrayWithCapacity: instead of -init...; thus, you aren't leaking an object
referenceArray = [[NSMutableArray alloc] init];
// Same as above
stemArray = [NSMutableArray arrayWithCapacity:numberOfStems];
stemArray = [[NSMutableArray alloc] init];
for ( int i = 1; i <= numStems; i++ ) {
// This part looks fine
NSString *soundName = [NSString stringWithFormat:@"stem-%i", i];
NSString *soundPath = [[NSBundle mainBundle] pathForResource:soundName ofType:@"mp3"];
NSURL *soundFile = [[NSURL alloc] initFileURLWithPath:soundPath];
[referenceArray addObject:soundFile];
// If you are in ARC, you are fine. If non-ARC, you are leaking soundFile and need to do:
// [soundFile release];
}
Исходя из вашего исходного описания, вы, вероятно, захотите переместить объявление stemArray в конец и использовать -copy или -mutableCopy:
stemArray = [referenceArray mutableCopy]; // If stemArray is defined as an NSMutableArray
или:
stemArray = [referenceArray copy]; // If stemArray is defined as an NSArray