2011-04-23 5 views

답변

47

그렇게 여러 가지 방법이 있습니다 :

NSArray *newArray = [NSMutableArray arrayWithArray:oldArray]; 

NSArray *newArray = [[[NSMutableArray alloc] initWithArray:oldArray] autorelease]; 

NSArray *newArray = [[oldArray mutableCopy] autorelease]; 

이 모든하지만, 얕은 복사을 생성합니다.

(편집 : 당신은 ARC와 작업하는 경우, 그냥 autorelease에 대한 호출을 삭제합니다.)

전체 복사본이 대신 사용을 위해 : 지적

NSMutableArray *newArray = [[[NSMutableArray alloc] initWithArray:oldArray copyItems:YES] autorelease]; 

가치 : 분명한 이유 때문에 후자는 배열의 모든 요소 객체가 NSCopying을 구현해야합니다.

+0

얕은 복사본과 깊은 복사본으로 무엇을 의미합니까 ?? – Supertecnoboff

+0

@Supertecnoboff : https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Collections/Articles/Copying.html – Regexident

+0

고맙습니다. 매우 흥미 롭습니다. 나는이 개념을 결코 알지 못했다. – Supertecnoboff