Just create a new PLIST in Xcode. File > New File > Other > Property List File. Name it anything you would like, just change :@"filename" to the name of your file, NOT including ".plist".
Once you begin to edit you will see your Root which is your dictionary (<dict>) . Add as many arrays as you would like.
Change [categoryDic valueForKey:@"items"]; to whatever you name your Array. For example
Code:
NSMutableArray *items = [categoryDic valueForKey:@"sillyjokes"];
If the name of your array is "sillyjokes". ' I've uploaded an example PLIST file.
You insert the code I posted before in the action of your button. since the NSString *fileContents is used multiple times its easier to place it in your header file. Same with UILabel *someLabel;
Code:
- (IBAction)randomSillyJoke:(id)sender {
fileContents = [[NSBundle mainBundle] pathForResource:@"sillyjokes" ofType:@"plist"];
NSDictionary *sillyJokes = [[NSDictionary alloc] initWithContentsOfFile:fileContents];
NSMutableArray *sillyjokes = [categoryDic valueForKey:@"jokes"];
int randomNumber = arc4random() % [items count];
joke = [sillyJokes objectAtIndex:randomNumber];
[someUILabel setText:joke];
}
- (IBAction)randomDirtyJoke:(id)sender {
fileContents = [[NSBundle mainBundle] pathForResource:@"dirtyjokes" ofType:@"plist"];
NSDictionary *dirtyJokes = [[NSDictionary alloc] initWithContentsOfFile:fileContents];
NSMutableArray *dirtyjokes = [categoryDic valueForKey:@"jokes"];
int randomNumber = arc4random() % [items count];
joke = [dirtyJokes objectAtIndex:randomNumber];
[someUILabel setText:joke];
}
Hope this helps