Tuesday, April 5, 2011

Passing array to another class - Objective C

I manage to pass the following array from MessagesTableViewController.m to arraySelectedCategory in another class called MessageDetailViewController.m:

self.messageDetailViewController.arraySelectedCategory =
        [[NSMutableArray alloc] initWithObjects:@"Value 1",@"Value 2", @"Value 3", nil];

but how do I hand over an array stored in: NSMutableArray *categories;

self.messageDetailViewController.arraySelectedCategory = ?????

Thanks!

From stackoverflow
  • I take it that you want a copy of the categories array?

    self.messageDetailViewController.arraySelectedCategory = [categories copy];
    calmh : @Darko Yes. And if that's not what your're looking for, a simple `self.messageDetailViewController.arraySelectedCategory = categories` should do.
    Darko Hebrang : Thanks! It helped a lot. I am still new to Objective C.

0 comments:

Post a Comment