13.07.2015 Views

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 9: Writing an Application 345loadingPeople property on the class. There will be one for each address type (i.e. one for eachXPC method called).Listing 9-93 shows the code used to populate this list. Once it’s populated, the resulting array isset as the content of the connected NSArrayController; this task takes place on the main queuesince it will prompt a UI update.Listing 9-93. Populating the People ListNSArray * people = result;NSMutableArray * contentArray = [[NSMutableArray alloc] initWithCapacity: [people count]];for ( NSDictionary * person in people ){NSMutableDictionary * mine = [person mutableCopy];// add the remaining pieces necessary for our UI etc.NSString * first = person[@"firstName"];NSString * last = person[@"lastName"];if ( first != nil && last != nil )mine[@"fullName"] = [NSString stringWithFormat: @"%@ %@", first, last];else if ( first != nil )mine[@"fullName"] = first;else if ( last != nil )mine[@"fullName"] = last;if ( first != nil )mine[@"firstName"] = first;if ( last != nil )mine[@"lastName"] = last;mine[@"loadingPhones"] = @NO;mine[@"loadingEmails"] = @NO;mine[@"loadingAddresses"] = @NO;mine[@"phoneNumbers"] = [NSMutableArray new];mine[@"emails"] = [NSMutableArray new];mine[@"addresses"] = [NSMutableArray new];}// pack it into the output array[contentArray addObject: mine];// now we want to update the UI by setting the content of our// peopleController outlet to this array// this hits the UI though, so we do it on the main threaddispatch_async(dispatch_get_main_queue(), ^{[self.peopleController setContent: contentArray];});Loading addresses, as mentioned above, is performed on demand as the user changes theirselection in the list of people. To implement this, the controller implements an NSTableViewwww.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!