1 #import<Foundation/Foundation.h>2 3 @interfacePerson:nsobject4 5@property (nonatomic, strong) NSString *PersonName;6- (ID) Initwithname: (NSString *) name;7 8 @end9 Ten #import "Person.h" One A @implementation Person - -- (ID) Initwithname: (NSString *) name the { - if(self =[Super init]) - { -_personname =name; + } - returnSelf ; + } A at @end - - #import<Foundation/Foundation.h> - #import "Person.h" - intMainintargcConst Char*argv[]) - { in @autoreleasepool - { toPerson *P1 = [[Person alloc] Initwithname:@"Zhang San"]; +Person *P2 = [[Person alloc] Initwithname:@"John Doe"]; -Person *P3 = [[Person alloc] Initwithname:@"Harry"]; theNsarray *personarray =[[Nsarray alloc] initwithobjects:p2, p3, nil]; * $Nsmutablearray *array =[[Nsmutablearray alloc] init];Panax Notoginseng //adding elements - [Array addobject:p1]; the [Array Addobjectsfromarray:personarray]; +NSLog (@"%@", array); A //Delete Element the //Delete all elements in an array + //[Array removeallobjects]; - //Delete the last element of an array $ //[Array removelastobject]; $ //Delete the specified element - [Array removeobject:p2]; - //Delete the element with the specified subscript (note that the number of elements in the array will cause a crash in the subscript problem) the //[Array removeobjectatindex:2]; -NSLog (@"2.%@", array);Wuyi the //the position of the interchange element -[Array Exchangeobjectatindex:0Withobjectatindex:1]; WuNSLog (@"%@", array); - } About return 0; $}
Objective--c's foundation Frame's Nsmutablearray code