I create two mutable arrays – referenceArray & stemArray, I then fill the referenceArray with URLs. I’d like to make stemArray an exact copy of referenceArray. I gather that making
the assignment stemArray = referenceArray; is not correct (strange things happen when I try this). There must be a better way then simply creating a second loop & filling up stemArray that way? I’m still not very comfortable with pointers & I believe this situation is a potential minefield…any hints or suggestions? thanks in advance 🙂
referenceArray = [NSMutableArray arrayWithCapacity:numberOfStems];
referenceArray = [[NSMutableArray alloc] init];
stemArray = [NSMutableArray arrayWithCapacity:numberOfStems];
stemArray = [[NSMutableArray alloc] init];
for ( int i = 1; i <= numStems; i++ ) {
NSString *soundName = [NSString stringWithFormat:@"stem-%i", i];
NSString *soundPath = [[NSBundle mainBundle] pathForResource:soundName ofType:@"mp3"];
NSURL *soundFile = [[NSURL alloc] initFileURLWithPath:soundPath];
[referenceArray addObject:soundFile];
}
You’re overwriting pointers to your mutable arrays immediately after you create them – why are those
alloc/initlines in there? If you want a copy of an NSArray, just send it acopymessage: