In Swift1, we can get the short file name without the extension using the following code:
self.name = pathFilename.lastPathComponent.stringByDeletingPathExtension
While I was upgrading to Swift 2, this API is no longer available. With a warning message I should use NSURL. So the new code will be:
var filename = NSURL(fileURLWithPath: str).lastPathComponent filename = NSURL(fileURLWithPath: filename!).URLByDeletingPathExtension?.relativePath
This is too complex a change to the API. Is there a better way to make this easier?
ios filenames swift2
Howard
source share