Common operations for the Objective-c:nsmutablearray class

Source: Internet
Author: User

The content size of the variable group Nsmutablearray is variable, so its common operation is nothing more than adding and removing the check,

Some of them are: Create, add, delete, replace, insert, empty, etc...

//

Main.m

02-nsmutablearray

//

Created by Ma C on 15/8/18.

Copyright (c) 2015 BJSXT. All rights reserved.

//

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])

{

@autoreleasepool

{

Nsmutablearray variable Array

1. Create

1.1 Creating a mutable array from an immutable group

Nsarray *array = @[@1,@2,@3,@4,@5];

Nsmutablearray *mutablearray1 = [Nsmutablearray Arraywitharray:array];

1.2 Creating an empty mutable array

Nsmutablearray *mutablearray2 = [Nsmutablearray array];

1.3 Creating a fixed-size array

Nsmutablearray *mutablearray3 = [Nsmutablearray arraywithcapacity:10];

2. Adding objects

[Mutablearray1 addobject:@6];

[Mutablearray1 addobject:@3];

NSLog (@ "%@", mutablearray1);

3. Deleting objects

[Mutablearray1 removeobject:@3];

NSLog (@ "%@", mutablearray1);

[Mutablearray1 removelastobject];//Delete the last

[Mutablearray1 removeobjectatindex:2];//Delete by index

NSLog (@ "%@", mutablearray1);

4. Replacing objects

[Mutablearray1 Replaceobjectatindex:2 withobject:@10];

NSLog (@ "%@", mutablearray1);

4. Inserting objects

[Mutablearray1 insertobject:@3 Atindex:2];

NSLog (@ "%@", mutablearray1);

5. Clear All Objects

[Mutablearray1 removeallobjects];

NSLog (@ "%@", mutablearray1);

}

return 0;

}

Common operations for the Objective-c:nsmutablearray class

Related Article

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.