Skip to content
Cocoa Maker 6 - Arrays, Dictionaries, and Property Lists episode artwork

Mar 23, 2010

Cocoa Maker 6 - Arrays, Dictionaries, and Property Lists

from Cocoa Maker Hosted by Mr. Gecko

James (MrGeckosMedia.com), joined by, Eduardo (MegaEduX.com), and John (@ZimiPoder), shows how Dictionaries, Arrays and Property Lists works in Cocoa. 12:40 Example code from episode. #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Array"); NSArray *array = [NSArray arrayWithObjects:@"Orange", @"Apple", @"Banana", nil]; for (int i=0; i<[array count]; i++) { NSLog(@"%@", [array objectAtIndex:i]); } NSLog(@"Sorting Array"); array = [array sortedArrayUsingSelector:@selector(compare:)]; for (int i=0; i<[array count]; i++) { NSLog(@"%@", [array objectAtIndex:i]); } NSLog(@"Saving Property List"); [array writeToFile:[@"~/Desktop/array.plist" stringByExpandingTildeInPath] atomically:YES]; NSLog(@"Mutable Array"); NSMutableArray *mutableArray = [NSMutableArray array]; [mutableArray addObject:@"Apples"]; [mutableArray addObject:@"Oranges"]; [mutableArray addObject:@"Bananas"]; for (int i=0; i<[mutableArray count]; i++) { NSLog(@"%@", [mutableArray objectAtIndex:i]); } NSLog(@"Removing object Oranges"); [mutableArray removeObjectAtIndex:1]; for (int i=0; i<[mutableArray count]; i++) { NSLog(@"%@", [mutableArray objectAtIndex:i]); } NSLog(@"Dictionary"); NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Oranges", @"Name", @"Fruit", @"Type", [NSNumber numberWithBool:YES], @"Seeds", nil]; NSLog(@"Adding %@ with name %@", [dictionary objectForKey:@"Type"], [dictionary objectForKey:@"Name"]); [mutableArray insertObject:dictionary atIndex:1]; for (int i=0; i<[mutableArray count]; i++) { NSLog(@"%@", [mutableArray objectAtIndex:i]); } NSLog(@"Saving Property List using NSPropertyListSerialization"); NSData *xmlData = [NSPropertyListSerialization dataFromPropertyList:mutableArray format:NSPropertyListXMLFormat_v1_0 errorDescription:nil]; [xmlData writeToFile:[@"~/Desktop/mutableArray.plist" stringByExpandingTildeInPath] atomically:YES]; NSLog(@"Mutable Dictionary"); NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionary]; [mutableDictionary setObject:@"Salad" forKey:@"Name"]; [mutableDictionary setObject:@"Veggie" forKey:@"Type"]; [mutableDictionary setObject:[NSDate date] forKey:@"Time"]; [mutableDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"Seeds"]; NSLog(@"Adding %@ with name %@", [mutableDictionary objectForKey:@"Type"], [mutableDictionary objectForKey:@"Name"]); [mutableArray insertObject:mutableDictionary atIndex:0]; for (int i=0; i<[mutableArray count]; i++) { NSLog(@"%@", [mutableArray objectAtIndex:i]); } NSLog(@"Saving Binary Property List"); NSData *binaryData = [NSPropertyListSerialization dataFromPropertyList:mutableArray format:NSPropertyListBinaryFormat_v1_0 errorDescription:nil]; [binaryData writeToFile:[@"~/Desktop/bina ry.plist" stringByExpandingTildeInPath] atomically:YES]; [pool drain]; return 0; } Keynote used in this Episode Keynote in PDF Format

Episode details come from the podcast's RSS feed.

Embed this episode

Ready to play

Cocoa Maker 6 - Arrays, Dictionaries, and Property Lists

No transcript yet.

Requests help us decide what to transcribe next.

AI, Government, and the Future Corner Alliance Welcome to AI, Government, and the Future, a podcast by Corner Alliance. We explore the intersection of artificial intelligence, government, and the future. Join us as we dive into the latest AI advancements, government policies, and innovative strategies to shape the future of our society. Whether you're a policy maker, venture capitalist, academic, or industry leader, this podcast will provide valuable insights and thought-provoking discussions to help you navigate the evolving landscape of AI and its impact on government. Tune in to AI, Government, and the Future to stay ahead in this transformative era. The Bootloader Paul Cutler and Tod Kurt A monthly podcast loading you up with news, project updates and product talk from the CircuitPython and maker communities. Hosted by Tod Kurt and Paul Cutler. Hack Learning Mark Barnes Learn quick and easy ways to improve education, leadership, and parenting: How to replace traditional homework; how to improve leadership; how to integrate new technology; how to assess for learning; how to eliminate useless meetings; how to engage even the most reluctant learners; how to inspire a lifelong love of reading; how to combine writing with the maker space; how to take learning mobile; how to improve social media strategies. Teacher/author/global influencer Mark Barnes, creator of the Bestselling Hack Learning Book Series, explains precisely what's wrong with education and what you can do about it, tomorrow; because you don't need a 5-year plan. Learn more at http://10publications.com.

Frequently asked questions

When was this Cocoa Maker episode published?

This episode was published on March 23, 2010.

Can I download this Cocoa Maker episode?

Yes. Use the download control on the episode player to save the publisher-provided media file.