- (void)viewDidLoad
{
NSError *error;
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [path objectAtIndex:0];
NSString *path1 = [documentDirectory stringByAppendingPathComponent:@"data.plist"];
NSFileManager *filemanager = [NSFileManager defaultManager];
NSLog( @"%@" ,documentDirectory) ;
if(![filemanager fileExistsAtPath:path1])
{
NSString *bundle = [[NSBundle mainBundle]pathForResource:@"data" ofType:@"plist"];
[filemanager copyItemAtPath:bundle toPath:path1 error:&error];
}
NSMutableDictionary *dictMioDB = [[NSMutableDictionary alloc] initWithContentsOfFile:documentDirectory] ;
NSMutableArray *arryRandomNumber =[[NSMutableArray alloc]init];
while (arryRandomNumber.count<10) {
NSInteger randomNumber=1+arc4random()%10;
if (![arryRandomNumber containsObject:[NSString stringWithFormat:@"%d",randomNumber]]) {
[arryRandomNumber addObject:[NSString stringWithFormat:@"%d",randomNumber]];
[dictMioDB setValue: arryRandomNumber forKey:?????????];
}
continue;
}
[dictMioDB writeToFile:path1 atomically:YES];
NSLog(@"%@ - %@",arryRandomNumber,[arryRandomNumber objectAtIndex:2]);
//[data writeToFile: path atomically:YES];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
我是目标 c 的新手,我正在尝试将元素数组写入我的 plist