操作沙盒中的数据

- (void)saveArray

{

// 1.获得沙盒根路径

NSString*home =NSHomeDirectory();

// 2.document路径

NSString*docPath = [homestringByAppendingPathComponent:@"Documents"];

// 3.新建数据

NSArray*data =@[@"jack",@10,@"ffdsf"];

NSString*filepath = [docPathstringByAppendingPathComponent:@"data.plist"];

[datawriteToFile:filepathatomically:YES];



- (IBAction)read {

// 1.获得沙盒根路径

NSString*home =NSHomeDirectory();

// 2.document路径

NSString*docPath = [homestringByAppendingPathComponent:@"Documents"];

// 3.文件路径

NSString*filepath = [docPathstringByAppendingPathComponent:@"data.plist"];

// 4.读取数据

NSArray*data = [NSArrayarrayWithContentsOfFile:filepath];

NSLog(@"%@", data);

}

你可能感兴趣的:(操作沙盒中的数据)