To add the object in array in for Loop we have several methods: first we can have to simply add those objects to the array then we can add them using for loop in array..... **IN example:** we have a simple object *object that we added 3 times at diffrent index postion in array(**mutArray)..** And other method is to add the object from another array: for that we accessed the each object at current index from the array and added that to the another array(**myMutableArray**)...
- NSMutableArray *mutArray=[[NSMutableArray alloc]init];
- for(int i=0;i<=2;i++)
- {
- NSString *object=@"Hello";
- [mutArray addObject:object];
- }
- NSLog(@"Mutable Array==%@",mutArray);
- //if the object are in other array then
- NSArray *objArray=[[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",nil];
- NSLog(@"obje==%@",objArray);
- NSMutableArray *myMutableArray=[[NSMutableArray alloc]init];;
- for(int index=0;index<objArray.count;index++)
- {
- [myMutableArray addObject:[objArray objectAtIndex:index]];
- }
- NSLog(@"myMutable Array==%@",myMutableArray);
For such more Blogs you can visit to http://findnerd.com/NerdDigest
No comments:
Post a Comment