Showing posts with label How To Add Objects In Array Using For Loop. Show all posts
Showing posts with label How To Add Objects In Array Using For Loop. Show all posts

Thursday, 7 May 2015

Save the other Object in array using For loop










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**)...
  1. NSMutableArray *mutArray=[[NSMutableArray alloc]init];
  2. for(int i=0;i<=2;i++)
  3. {
  4. NSString *object=@"Hello";
  5. [mutArray addObject:object];
  6. }
  7. NSLog(@"Mutable Array==%@",mutArray);
  8. //if the object are in other array then
  9. NSArray *objArray=[[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",nil];
  10. NSLog(@"obje==%@",objArray);
  11. NSMutableArray *myMutableArray=[[NSMutableArray alloc]init];;
  12. for(int index=0;index<objArray.count;index++)
  13. {
  14. [myMutableArray addObject:[objArray objectAtIndex:index]];
  15. }
  16. NSLog(@"myMutable Array==%@",myMutableArray);

For such more Blogs you can visit to http://findnerd.com/NerdDigest