Quote:
Originally Posted by brandon0104
Probably one of the easiest ways is to read from a property list file (plist). To do this.
Code:
NSString *fileContents = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"plist"];
NSDictionary *jokeDic = [[NSDictionary alloc] initWithContentsOfFile:fileContents];
NSMutableArray *items = [categoryDic valueForKey:@"items"];
After you've read your data from your plist file. You can then select a random joke from the items array.
Code:
int randomNumber = arc4random() % [items count];
NSString *joke = [items objectAtIndex:randomNumber];
[someUILabel setText:joke];
Here is an example PLIST file.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<string>joke 1</string>
<string>joke 2</string>
<string>joke 3</string>
</array>
</dict>
</plist>
I think that should work, if it doesn't let me know.
|
Thanks for all the help that you gave out I have a question how can you set
Code:
int randomNumber = arc4random() % [items count];
NSString *joke = [items objectAtIndex:randomNumber];
[someUILabel setText:joke];
to change in sequence on the plist positive or set it to change negative from where is already is?