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