Passing a NSArray between classes

Posted by Althane on Stack Overflow See other posts from Stack Overflow or by Althane
Published on 2010-03-15T21:22:14Z Indexed on 2010/03/15 21:39 UTC
Read the original article Hit count: 546

Filed under:
|
|

So, my second question based off of this application I'm teaching myself Objective C with. I have a Data Source class, which for now looks mostly like:

- (id) init
{
    if (self = [super init]){
    listNames =  [[NSArray alloc] initWithObjects: @"Grocery", @"Wedding", @"History class",@"CS Class",@"Robotics",@"Nuclear Sciences",
                  @"Video",@"Library",@"Funeral", nil];
    NSLog(@"%@",listNames);
    }
    return self;
}

The .h looks as follows:

@interface MainViewDataSource : NSObject {
    NSArray *listNames;
}

@property (nonatomic, retain) NSArray *listNames;
-(NSArray *)getListNames;

So that's where I make it. Now the problem is that when I try to get the array listNames, it returns nothing.

The following piece:

NSArray* data = [listData listNames];

Is supposed to put the information in listNames in data, but... isn't. Since I'm rather used to JAva, I'm betting this is an Objective C quirk that I don't know how to fix. Which is why I'd be here asking for help. What's the proper way to pass around NSArrays like this?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone