AaoIi
AaoIi

Reputation: 8396

stringByExpandingTildeinPath is unavailable

I am getting the following error in Swift 2 after converting my project:

stringByExpandingTildeinPath is unavailable: use stringByExpandingTildeinPath on NSString instead

This is the code I'm using to share with whatsapp in Swift 1.2, the error at line 3:

                let filename = "myimage.wai"
                let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, false)[0] as NSString
                let destinationPath = documentsPath.stringByAppendingString("/" + filename).stringByExpandingTildeInPath

Upvotes: 2

Views: 947

Answers (1)

Code Different
Code Different

Reputation: 93181

Why did you ask for it to not expand the ~ then expend it by yourself? Much simpler to let the API handle it by itself:

let filename = "myimage.wai"
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let destinationPath = documentsPath + "/" + filename

Upvotes: 3

Related Questions