如何使用以下代码删除我保存的NSDocumentDirectory
数据。
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullFileName2 = [NSString stringWithFormat:@"%@nameArray", documentsDirectory];
nameArray=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName2];
[nameArray addObject:nameField.text];
[nameArray writeToFile:fullFileName2 atomically:NO];
答案 0 :(得分:2)
试试这个:
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullFileName2 = [NSString stringWithFormat:@"%@nameArray", documentsDirectory];
[[NSFileManager defaultManager] removeItemAtPath:fullFileName2 error: NULL];
答案 1 :(得分:1)
试试这个,
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullFileName2 = [nameArray objectAtIndex:0];
[[NSFileManager defaultManager] removeItemAtPath:fullFileName2 error: NULL];