NSMutableArray arrayWithArray: vs initWithArray:

They work in my application without any noticeable difference:

1)

theArray = [[NSMutableArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:theData]];

2)

theArray = [NSMutableArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:theData]];
[theArray retain];

However, are they really equivalent? (1) has a alloc statement, while (2) does not. Preferred than another?

+3
source share
1 answer

The effect is the same. But (2) is less efficient (convenient method = alloc + init + autorelease).

  • alloc → INIT
  • alloc -> init -> autorelease -> save

The preferred way is not to copy the array.

theArray = [[NSKeyedUnarchiver unarchiveObjectWithData:theData] retain];

By the way, I notice that you asked a lot of basic questions about developing iPhone OS. Check out these guides first .

+5
source

Source: https://habr.com/ru/post/1765584/


All Articles