Question

I'm just delving into Objective C and Cocoa Touch and I'm trying to build an app for personal use.

My goal is to create an app that displays a randomized NSString in a center window on the iPhone screen while also displaying a scrollable list of associated NSStrings in another window on the side of the screen.

For example: if the center NSString is the name of an animal, such as "Lion", the NSStrings on the list next to it would also be animals (e.g., "Tiger", Snow Leopard", etc.)

I would like to create "packages" of associated NSStrings, have the program randomly select a "package", randomly display one of its NSStrings in the center, and simultaneously display a list of the other NSStrings in the package in the scrollable side window. After a given time interval the program would then loop and select another NSString, excluding those in the previously displayed "package".

My main interest is how to create such "packages" of NSStrings. Is it feasible to use NSDictionary or NSArray to create them?

Since I am just starting out I am hoping that someone can point me in the right direction in my research so that I know what tools I should use to begin experimenting.

I'd very much appreciate any recommendations or example code.

Thanks!

Was it helpful?

Solution

Use both NSArray and NSDictionary for it.

For example:

NSArray *animalArray = [NSArray arrayWithObjects:@"cat", @"dog", ... , nil];
NSArray *drinkArray = [NSArray arrayWithObjects:@"coke, @"tea", ... , nil];
...

NSMutableDictionary *wordsDictionary = [[NSMutableDictionary alloc] init];
[wordsDictionary addObject:animalArray forKey:@"animal"];
[wordsDictionary addObject:drinkArray forKey:@"drink"];
...

And you can get all keys using [NSDictionary allKeys]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top