I'm trying to learn Swift 3 with translating a code from Swift 2. In swift 2, I see the code like this:
return fullPath.stringByAppendingPathComponent(name)
But, when I try in Swift 3, I've got similiar code, but like this:
return fullPath.strings(byAppendingPaths: [name])
The issue is, return type in the 1st code is String (and that's the output I need from the lesson I learn), but return type in 2nd code should be [String].
The other issue is, in Swift 2 the code should be:
imgData?.WriteToFile(fullPath, atomicaly:Bool)
But in Swift 3, I only can input code like this:
imgData.Write(to: URL , option: WritingOption) throws
But in some examples, there's .Write(toFile: , atomically:) but I can't find it in Xcode.
Am I translating incorrectly or using both Swift 2 and Swift 3 incorrectly?
Regarding the first part of your question , as dan stated in the comments you should be using fullPath.appendingPathComponent(name)
instead.
Regarding your second question:
The main difference between writeToFile
and write(to:
is the fact that the first is for String
s and the seconds is for NSData
.
Somewhat related:
According to the NSData Class Reference
In iOS 2.0+ you have:
write(to:atomically:)
and
write(toFile:atomically:)
Given:
Since at present only file:// URLs are supported, there is no difference between this method and writeToFile:atomically:, except for the type of the first argument.
None of this has changed in Swift 3 according to the Swift Changelog .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.