stringByAppendingPathComponent不可用 [英] stringByAppendingPathComponent is unavailable

查看:1835
本文介绍了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 is unavailable: use URLByAppendingPathComponent on NSURL instead.


推荐答案

看起来在Swift 2.0中删除了 stringByAppendingPathComponent 方法,所以错误信息建议使用:

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()已替换为 ap pendingPathComponent()所以改为:

let writePath = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("instagram.igo")

这篇关于stringByAppendingPathComponent不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆