Created
March 9, 2014 05:04
-
-
Save keicoder/9443131 to your computer and use it in GitHub Desktop.
objective-c : generate random number with array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//generate random number with array | |
- (void)awakeFromInsert //invoked automatically by the Core Data framework when the receiver is first inserted into a managed object context. | |
{ | |
[super awakeFromInsert]; | |
NSString *quotesFilePath = [[NSBundle mainBundle] | |
pathForResource:@"QuotesList" | |
ofType:@"plist"]; | |
NSArray *quotesArray = [NSArray arrayWithContentsOfFile:quotesFilePath]; | |
NSLog (@"quotesArray: %@", quotesArray); | |
NSUInteger quoteIndex = arc4random() % [quotesArray count]; //generate random number | |
NSDictionary *quoteDictionary = quotesArray[quoteIndex]; | |
NSLog (@"quoteDictionary: %@", quoteDictionary); | |
[self setPrimitiveValue:quoteDictionary[@"personName"] | |
forKey:@"personName"]; | |
[self setPrimitiveValue:quoteDictionary[@"famousQuote"] | |
forKey:@"famousQuote"]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment