what does -arrayWithArray actually DO?

前端 未结 4 609
执笔经年
执笔经年 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:12

    GNUstep, the GNU implementation of the OPENSTEP spec from which Cocoa and Cocoa Touch descend, implements +arrayWithArray: as follows:

    /**
     * Returns a new autoreleased NSArray instance containing all the objects from
     * array, in the same order as the original.
     */
    + (id) arrayWithArray: (NSArray*)array
    {
      id    o;
    
      o = [self allocWithZone: NSDefaultMallocZone()];
      o = [o initWithArray: array];
      return AUTORELEASE(o);
    }
    

    http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSArray.m?view=markup

提交回复
热议问题