1

I have a program that will be grabbing a image from our server for the app, however we want to save the image onto the iOS app for caching purposes.

The url would be similar to this.

http://www.example.com/image/app_name/mypicture.png

I need a way to get the image name (mypicture) and the extension (.png) into 2 different strings to save it.

How would I accomplish this using a NSscanner?

Thanks

Dfranc3373
  • 2,048
  • 4
  • 30
  • 44

1 Answers1

1

You wouldn't use a scanner. Use the NSURl method absoluteString to get the path and then use NSString methods pathExtension, stringByDeletingPathExtension and finally lastPathComponent to get the extension and name. You could also use the NSURL method resourceValuesForKeys:error: to get the name with the NSURLLocalizedNameKey.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Well, `NSURL` has methods `-pathExtension`, `-URLByDeletingPathExtension`, and `-lastPathComponent`, so there's no need to fall back to the `NSString` methods. – Ken Thomases Apr 21 '12 at 12:07