그래오늘은이거야

object c [IOS] NSArray, NSMutableArray How to use? or Difference 사용법 또는 차이점 본문

세상 개발/IOS(Objective-c)

object c [IOS] NSArray, NSMutableArray How to use? or Difference 사용법 또는 차이점

jinhongstar 2020. 1. 3. 10:14
728x90
반응형

안녕하세요 Leo 입니다.

Hi my name is Leo 

 

제가 코딩하면서 가끔 잊어 버려서 여기에 메모를 해 놓겠습니다!

I forget sometimes when I'm coding, so I'll take a note here!

 

 

NSArray , NSMutableArray 의 차이점은!!

The difference between NSAray and NSMutableArray is!!

 

NSArray 의 대입 또는 복사 한 값은 삭제및 수정이 되지 않습니다. 

One value of NSAray college entrance or copy cannot be deleted and modified.

 

하지만  NSMutableArray을 사용하여 HTTP통신이나 AFNetwork로 받아온 Json 파일을 copy 후에 수정 삭제 삽입이 가능합니다.

However, you can use NSMutableArray to copy the Json file you received over HTTP or AFNetwork before you insert the modified deletion.

 

Swift 로 말하자면 let, var의 차이 같습니다!!

As for Swift, let me guess, bar difference!!

 

내부적인 NSMutableArray의 레퍼런스를 보면 NSArray를 상속받아서 수정하게 만든것 같습니다.

Internal NSMutableArray references indicate that the NSAray was inherited and modified.

 

생성할때 

new를 할때 사용 방법입니다. 

저는 [[init] alloc] 보다는 new를 선호합니다.

 

 

NSMutableArray *trucksArray = [@[@"1", @"a"] mutableCopy];

          

NSMutableArray *jsonData = [NSMutableArray new];

            [jsonData addObject:@"aaa"];

            [jsonData addObject:@"bbb"];

            [jsonData addObject:@"ccc"];

           

         

그리고 현재 xcode 11버전에서는 addObject 가 링크가 안걸리는 버그가 있습니다.

 

그냥 무시하고 copy  해서 사용하면 작동은 잘 됩니다!

 

방법은 두가지 상황에 맡게 오브젝트를 잘 사용하세요

반응형
Comments