简体   繁体   English

xcode7 / swift 2.0中不推荐使用的方法

[英]Deprecated methods in xcode7/swift 2.0

I am in the middle of updating my app which was built in ios 8 to ios9 by using xcode7/swift 2.0. 我正在使用xcode7 / swift 2.0将内置于ios 8的应用程序更新为ios9。 Like many other people, my app crashed very heavily. 像许多其他人一样,我的应用程序崩溃非常严重。 The basic concept of my app is to let users to upload videos/images to a certain event. 我的应用程序的基本概念是允许用户将视频/图像上传到特定事件。 Right now, I am having an error message saying 现在,我收到一条错误消息说

object not found for update (Code: 101, Version: 1.9.0) 找不到要更新的对象(代码:101,版本:1.9.0)

from parse. 从解析。 I thought it was Parse's error at first but figured out I may have made some dumb mistakes while I was updating codes. 我最初以为是Parse的错误,但发现我在更新代码时可能犯了一些愚蠢的错误。 If you can take a look at the changes I made and point out the errors I made, it would be super helpful. 如果您可以查看我所做的更改并指出我所做的错误,那将非常有帮助。

I changed following: 我更改了以下内容:

var outputURL = NSURL.fileURLWithPath(NSTemporaryDirectory().stringByAppendingPathComponent("\(filename)").stringByAppendingString(".mp4"))

to

var outputURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("\(filename).mp4")

I made this change because stringByAppendingString is deprecated now. 我进行了更改,因为现在不推荐使用stringByAppendingString。

Other change i made is: 我所做的其他更改是:

let filename = (outputFileUrl.absoluteString.stringByDeletingPathExtension.lastPathComponent ?? "video") + "-c"

to

let filename = (outputFileUrl.URLByDeletingPathExtension?.lastPathComponent ?? "video") + "-c"

I am pretty sure I did right with converting functions. 我很确定我对转换函数的处理正确。 It would be greatly appreciated if anyone can point out what I did wrong in those two changes. 如果有人能指出我在这两个更改中做错了什么,将不胜感激。

The difference of the first example is: 第一个示例的区别是:

  • The former syntax creates an NSString object 前一种语法创建一个NSString对象
  • The new syntax creates an NSURL object 新语法创建一个NSURL对象

Either use the URL related API for example instead of …contentsOfFile use …contentsOfURL or get the path of the URL from the path property 例如,使用URL相关的API代替…contentsOfFile使用…contentsOfURL或从path属性获取URL的path

let outputURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("\(filename).mp4").path!

The second example returns a string with percent encoded special characters in the former syntax and a string without percent encoding in the new syntax. 第二个示例返回一个字符串,该字符串在以前的语法中具有百分比编码的特殊字符,而在新语法中返回了一个不具有百分比编码的字符串。 You might add the percent encoding. 您可以添加百分比编码。

An alternative method to keep the older syntax is to cast the String to NSString eg 保留旧语法的另一种方法是将String NSStringNSString例如

let filename = (((outputFileUrl.absoluteString as NSString).stringByDeletingPathExtension as NSString).lastPathComponent ?? "video") + "-c"

but I recommend to use the URL related API 但我建议使用与网址相关的API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM