Domanda

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];
È stato utile?

Soluzione

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

It may help you.

Altri suggerimenti

Mistake is in the line below

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

It should be

NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d",n]];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top