Pages

Wednesday, January 23, 2013

How to work with NSMutable Array and For Loop in xCode

first declare the Mutable Array in filename.h



#import <Foundation/Foundation.h>

@interface FileNameAsClassName: NSObject
{
    NSMutableArray *users;
}
@property(nonatomic,strong) NSMutableArray *users;
@end;

Now define this users array in filename.m


#import "FileNameAsClassName.h"

@implementation FileNameAsClassName
@synthesize users;

Now use this to add Objects in any function, where you required, after initialize

//Initializing
users = [[NSMutableArray alloc] init];

//Inserting Objects in some function, where required
[users addObject:someObjectName];


Now use this as below in required function 


for(int i=0;i<users.count;i++)
{
    someObjectName = [users objectAtIndex:i];
    //Now use someObjectName as Obejct, which you have inserted
}

No comments:

Post a Comment