Posts

Showing posts from May, 2017

Copy Vs Mutable Copy in iOS

It's found very confusing for most of the folks, who is not having much experience in Objective-C. Before starting I just to say: Just remember below lines- 1 - copy always creates an immutable copy means you can not modify the object. 2 - mutableCopy always creates a mutable copy  means you can modify the object Here onwards I try to explain copy and mutable copy with some examples: copy: NSArray *obj = [ NSArray arrayWithObjects : @"1" , @"2" , nil ]; NSArray *copyObj = [obj copy ]; NSArray *mutableObj = [obj mutableCopy ]; When you try to see the details of copyObj its clearly shows  __NSArrayI which tells that you can not modify this object Printing description of copyObjy: <__nsarrayi 0x6080000238a0="">( 1, 2 ) Same way  When you try to see the details of mutableObj its clearly shows  __NSArrayM which tells that you can modify this object Printing description of mutableObjy: <__nsarr