沙盒中存取删数据

#pragma mark -存储数据

-(void)SaveString:(NSString*)UrlStr

{

// 1.获得沙盒根路径

NSString*home =NSHomeDirectory();

// 2.document路径

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

NSArray*data =@[UrlStr];

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

[datawriteToFile:filepathatomically:YES];

}

读取数据

- (NSArray*)readData {

// 1.获得沙盒根路径

NSString*home =NSHomeDirectory();

// 2.document路径

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

// 3.文件路径

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

// 4.读取数据

NSArray*data = [NSArrayarrayWithContentsOfFile:filepath];

returndata;

}

删除数据

NSString *home = NSHomeDirectory();

// 2.document路径

NSString *docPath = [home stringByAppendingPathComponent:@"Documents"];

NSFileManager * fileManager = [[NSFileManager alloc]init];

[fileManager removeItemAtPath:docPath error:nil];

你可能感兴趣的:(沙盒中存取删数据)