Replace extension of a filename in swift

ios, swift

Solution

`stringByAppendingPathExtension` no longer works in Swift 2.0 (if you are using `String`). But it does still work for `NSString`. So you can do:

var storePath = (NSSearchPathForDirectoriesInDomains(.DocumentDirectory , .UserDomainMask, true)[0]) as NSString
storePath = storePath.stringByAppendingPathExtension("model.sqlite")!

Problem

Given an string with format `filename.fileextension` I want to replace the fileextension with `newextension`. How can I do it? In java it would be ``` foo.substring(0, foo.lastIndexOf(".")) + ".newextension" ```

Original source