本文介绍了stringByAppendingPathComponent 不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用在 Instagram 上分享照片,为此它首先将它保存在一个临时目录中:
My app shares photo on Instagram, to do this it first saves it on a temporary directory:
let writePath = NSTemporaryDirectory().stringByAppendingPathComponent("instagram.igo")
它适用于 Swift 1.2
,但不适用于 Swift 2.0
.
It was working on Swift 1.2
, but does not work on Swift 2.0
.
给定的错误信息是:
stringByAppendingPathComponent 不可用:在 NSURL 上使用 URLByAppendingPathComponent 代替.
推荐答案
看起来方法 stringByAppendingPathComponent
在 Swift 2.0 中被删除了,所以错误信息建议使用:
It looks like the method stringByAppendingPathComponent
is removed in Swift 2.0, so what the error message suggests is to use:
let writePath = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("instagram.igo")
更新:
URLByAppendingPathComponent()
已被 appendingPathComponent()
取代,所以改为:
URLByAppendingPathComponent()
has been replaced by appendingPathComponent()
so instead do:
let writePath = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("instagram.igo")
这篇关于stringByAppendingPathComponent 不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!