문제

I want a folder in document directory with constant name. Now i want to save the folder with a variable name, like i have an variable "n" and the value of "n" is changeable now I want to save the folder with the name of "n" value. my code is as follow but it give me error.

 NSInteger n = 3;    
 NSError *error;

NSString *aDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:@"%d",n];

[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
도움이 되었습니까?

해결책

NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d",n];

It may help you.

다른 팁

Mistake is in the line below

NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:@"%d",n];

It should be

NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d",n]];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top