开发者

Array copying and deleting

开发者 https://www.devze.com 2023-01-24 13:06 出处:网络
I have setup NSCopying and I can copy an array successfully. theArray = [[NSMutableArray alloc] initWithArray:results.availableData

I have setup NSCopying and I can copy an array successfully.

theArray = [[NSMutableArray alloc] initWithArray:results.availableData 
copyItems:YES];

When I am finished with theArray and all its data is junk I would like开发者_如何学编程 to get another fresh copy of the data from results.availableData array.

Whats the best and safest way to do this?

Should i

[theArray release];
theArray = [[NSMutableArray alloc] initWithArray:results.availableData 
copyItems:YES];

So release theArray then alloc and init it again?

Many Thanks -Code


How about simply:

[theArray setArray: [[NSArray alloc] initWithArray: results.availableData
    copyItems: YES] autorelease]];

And be done with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消