2011-01-20 17 views

Odpowiedz

43

Spróbuj tego:

NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
NSError *error = nil; 
for (NSString *file in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folderPath error:&error]) { 
    [[NSFileManager defaultManager] removeItemAtPath:[folderPath stringByAppendingPathComponent:file] error:&error]; 
} 
2

Swift 3.x

let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] 
guard let items = try? FileManager.default.contentsOfDirectory(atPath: path) else { return } 

for item in items { 
    // This can be made better by using pathComponent 
    let completePath = path.appending("/").appending(item) 
    try? FileManager.default.removeItem(atPath: completePath) 
} 
Powiązane problemy