Friday, May 31, 2013

NSArray initWithObjects example in Objective C (iOS).


NSArray initWithObjects

Initializes a newly allocated array by placing in it the objects in the argument list.

- (id)initWithObjects:(id)firstObj, ...

Parameters
firstObj, ...
A comma-separated list of objects ending with nil.

Return Value of [NSArray initWithObjects]
An array initialized to include the objects in the argument list. The returned object might be different than the original receiver.

Discussion of [NSArray initWithObjects]
After an immutable array has been initialized in this way, it can’t be modified.

NSArray initWithObjects example.
NSArray *list = [[NSArray alloc]
                initWithObjects:@"Christie, Agatha",
                @"Archer, Jeffrey", nil];
self.authorList = list;
[list release];

Example of [NSArray initWithObjects].
 - (void)viewDidLoad{
      [super viewDidLoad];

       NSArray *tempArray = [[NSArray alloc]
               initWithObjects:@"Christie, Agatha",
               @"Archer, Jeffrey", nil];
       self.authorList = tempArray;
       [tempArray release];

      NSString *titleString = @"Authors";
      self.title = titleString;
      [titleString release];
 }

NSArray initWithObjects example.
    allFeaturesAvailableTabBarItemArray = [[NSArray alloc] initWithObjects:
                                          issuesNavigationController,
                                          thumbsViewController,
                                          contentsViewController,
                                          searchViewController,
                                          favouritesViewController,
                                          contactViewController, nil];

End of NSArray initWithObjects example article.