random_names随机名字生成
// 先从txt文件中获取姓和名数组
- (void)getNames{
NSString *resourcePath1 = [[NSBundle mainBundle] pathForResource:@"FirstName" ofType:@"txt"];
NSString *resourcePath2 = [[NSBundle mainBundle] pathForResource:@"LastName" ofType:@"txt"];
NSLog(@".....%@",resourcePath1);
NSLog(@">>>> %@",resourcePath2);
NSData *firstData = [NSData dataWithContentsOfFile:resourcePath1];
NSData *lastData = [NSData dataWithContentsOfFile:resourcePath2];
NSString *firstStr= [[NSMutableString alloc] initWithData:firstData encoding:NSUTF8StringEncoding];
NSString *lastStr = [[NSMutableString alloc] initWithData:lastData encoding:NSUTF8StringEncoding];
char *Cstring = "\n"; //分割符
NSString *separatedString = [NSString stringWithUTF8String:Cstring];
_FirstNames = [firstStr componentsSeparatedByString:separatedString];
_LastNames = [lastStr componentsSeparatedByString:separatedString];
}
// 点击显示姓名
NSString *firstName = [_FirstNames objectAtIndex:arc4random()%(_FirstNames.count)];
NSString *lastName = [_LastNames objectAtIndex:arc4random()%(_LastNames.count)];
[_nameLabel setText:[NSString stringWithFormat:@"%@%@",firstName,lastName]];