我創建了兩個可變數組 - referenceArray & stemArray,然後用URL填充referenceArray。我想使stemArray成爲referenceArray的精確副本。我收集,使 賦值stemArray = referenceArray;是不正確的(奇怪的事情發生在我嘗試這個時)。必須有更好的方法,然後簡單地創建第二個循環&這樣填滿stemArray?我仍然不太滿意指針&我相信這種情況是潛在的雷區......任何提示或建議?在此先感謝:)製作數組副本
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];
}
我的程序不會不分配/初始化線正常運行(eventhough這是技術上的錯誤是在這種情況下工作) - 我需要的是 ReferenceArr ay = [[NSMutableArray alloc] initWithCapacity:numberOfStems]; 感謝您的幫助,「複製」信息正是我一直在尋找的。 – Octave1