Does ARC describe the need for temporary variables?

Without ARC compatibility we write

NSArray *items = [[NSArray alloc] initWithObjects: @"a", @"b", @"c", @"d", nil]; self.allItems = items; [items release]; 

I'm just wondering if we can use the ARC-enabled shortcut as follows:

 self.allItems = [[NSArray alloc] initWithObjects: @"a", @"b", @"c", @"d", nil]; 

Is it possible to exclude items when we use ARC? What is the best practice?

+4
source share
3 answers

Yes, you can exclude the items variable if you use ARC. I suggest you eliminate it if you do not need it elsewhere, and you do not think that this simplifies the understanding of the code. I would definitely eliminate this in your example.

+1
source

Yes, the second example you showed is great for ARC and probably desirable because it is more concise.

+3
source

The second example will work and become the best practice. With ARC, you no longer need to invoke save or release.

+1
source

All Articles