iphone - Cocoa Touch: Accessor method + memory needs clarification -


Please consider the problem of creating an array and return it to a parent object. Please see my code and comments below.

My question is this: why the method works three methods are one and two while not

  // ****** * ************** Master. M. *** ************************************************************************ ************************************************************************************************ ** // bus array and call accessor declared NSMutableArray * allElementTypes; AllElementTypes = [Element Object Balanced Elements]; // ******************************************************************************** (EXE_BAD_ACCESS) + (NSMutableArray *) badElements {NSMutableArray * Array = [[NSMutableArray alloc] initWithObjects: @ "crab", "@ poison", @ "snake"]; Return array; } // does not work (EXE_BAD_ACCESS) + (NSMutableArray *) badElements {return [NSMutableArray arrayWithObjects: @ "crab", @ "poison", @ "snake"]; } // WORKS + (NSMutableArray *) badElements {NSMutableArray * array = [[NSMutableArray alloc] init]; [Array addObject: @ "crab"]; [Array addObject: @ "poison"]; [Array addObject: @ "snake"]; Return array; // TODO: this memory}  release 

-arrayWithObjects: or -initWithObjects takes a zero is . End, variable length, list of arguments

You wrote:

[NSMutableArray arrayWithObjects: @ "crab", @ "poison", @ "snake"];

Where should it be written:

[NSMutableArray arrayWithObjects: @ "crab", @ "poison", @ "snake", zero];


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -