0
我保存圖像,但它只是自我複製,因爲我只設置了一個名字,但是我希望它能夠數起來,因此它不會自行更換。有沒有辦法做到這一點?保存時計數
NSArray *directoryNames = [NSArray arrayWithObjects:@"hats",@"bottoms",@"right",@"left",nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
for (int i = 0; i < [directoryNames count] ; i++) {
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:[directoryNames objectAtIndex:i]];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil]; //Create folder
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"hats"]; // "right" is at index 2, per comments & code
NSString *filePath = [folderPath stringByAppendingPathComponent:@"hats.PNG"]; // you maybe want to incorporate a timestamp into the name to avoid duplicates
NSData *imageData = UIImagePNGRepresentation(captureImage.image);
[imageData writeToFile:filePath atomically:YES];
}
檢查帽子夾中的文件的數量。使用++獲取它的計數並將其附加到要保存的文件名。 –
我知道它只是替代自己,但我不知道如何使用時間戳或其他更簡單的方法來阻止這種情況 – AppleDevram