Question

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];
Was it helpful?

Solution

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

It may help you.

OTHER TIPS

Mistake is in the line below

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

It should be

NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d",n]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top