Shah
Shah

Reputation: 5020

how to create Array of my NSObject class

I have created a new NSObject class as below:

@interface LoginObject : NSObject {

NSString *fName;
NSString *lName;
NSString *sessionId;
NSString *result;
NSString *response;
}

Now I can create an object of this type as:

LoginObject *login;

What do i need to do in order to create an NSMutableArray of my own NSObject class.

can any body guide? Thanks

Upvotes: 0

Views: 2083

Answers (3)

user1079903
user1079903

Reputation:

First create objects of your class,an array as -

    LoginObject *obj1 = [[LoginObject alloc]init];
    obj1.fName = @"xxxx";
    -----------

    LoginObject *obj1 = [[LoginObject alloc]init];
    obj1.fName = @"xxxx";
    -----------

    // create a array with above objects 
    // nil indicate end of array 

    NSMutableArray *users = [[NSMutableArray alloc]initWithObjects:obj1,obj2,...,nil];

   //if you want you can add other objects too -
   [users addObject:obj10];

Upvotes: 0

DanielS
DanielS

Reputation: 555

Just have a look at the NSMutableArray documentation here - http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html

Use one of the init or array methods. arrayWithObjects is the one I use most often.

Upvotes: 1

rishi
rishi

Reputation: 11839

In Which class you want to have this array, you can create-

@property (nonatomic, retain) NSMutableArray *loginObjectArray;

in implementation file-

LoginObject *myLoginObject = [[LoginObject alloc] init];
myLoginObject.fName = ---
......
[loginObjectArray addObject:myLoginObject];
....

Don't forget to initialize loginObjectArray.

Upvotes: 0

Related Questions