elliotrock
elliotrock

Reputation: 3420

Convert NSData to a NSURL

I have seen this done the other way. But I have a NSData object returned that is suppose to be a URL of an image file.

How do I do this convert a NSData object into a NSURL?

Thanks

Upvotes: 5

Views: 14855

Answers (1)

JustSid
JustSid

Reputation: 25318

You first need to convert the NSData object to an NSString object and then you can just create a NSURL with the new string.

 NSString *urlString = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding]; // Or any other appropriate encoding
 NSURL *url = [[NSURL alloc] initWithString:[urlString autorelease]];

Upvotes: 5

Related Questions