Objective--c's foundation Frame's Nsmutablearray code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.