what does -arrayWithArray actually DO?

前端 未结 4 620
执笔经年
执笔经年 2020-12-16 04:27

I want to see EXACTLY how it creates an array. How can I view the .m files that show how it\'s done?

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 05:16

    If you're asking what's the purpose of +arrayWithArray (besides being an autorelease wrapper around -initWithArray), I'd say it's this: Use it when you want to create an autoreleased copy of an array. In other words, you could see it like this:

    NSArray * original = /* ... */;
    NSArray * newArray = [NSArray arrayWithArray:original];
    

    Is equivalent to:

    NSArray * original = /* ... */;
    NSArray * newArray = [[original copy] autorelease];
    

    I'd say it's there for convenience to use when it fits your style.

提交回复
热议问题