2013-08-17 1 views
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]; 
    } 
+0

을 방지 할 수 있습니다. ++로 카운트하고 이름을 저장할 파일을 추가하십시오. –

+0

나는 그 자체를 대체하고 있지만 타임 스탬프 나 다른 것을 사용하는 것이 더 간단하다는 것을 어떻게 막을 지 모른다. – AppleDevram

답변

2

를 사용하여 타임 스탬프 값은 모자 폴더에있는 파일의 수를 확인 중복

+0

이 코드는 의연한 의미인가? 'time_t unixTime = (time_t) [[NSDate date] timeIntervalSince1970]; NSString * timestamp = [NSString stringWithFormat : @ "% ld", unixTime];'단지 같은 위치에 두는 것뿐입니다. 나는 그것이 그림의 이름을 업데이트 할 것이라고 생각하지 않는다. – AppleDevram