Reputation: 10563
I've saved the contents of server into a NSData. How do I copy the contents of NSData into a file.
Upvotes: 1
Views: 499
Reputation: 43
NSString *imagelist = Data;
NSData *yourimageFileData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imagelist]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *yourFilePath = [documentsDirectory stringByAppendingPathComponent:reString];
[yourimageFileData writeToFile:yourFilePath atomically:YES];
Upvotes: 1
Reputation: 443
Take a look at the NSData writeToFile:atomically: method. Just pass in the filename and it will do it for you.
Upvotes: 3