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