what is
static let ArchiveURL = DocumentsDirectory.URLByAppendingPathComponent("meals")
renamed to in Swift 3?
what is
static let ArchiveURL = DocumentsDirectory.URLByAppendingPathComponent("meals")
renamed to in Swift 3?
I'm sure you really wrote
static let archiveURL = documentsDirectory.AppendingPathComponent("meals")
instead of
static let archiveURL = documentsDirectory.appendingPathComponent("meals")
Try copying and pasting the following code into your class or struct:
static let documentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
static let archiveURL = documentsDirectory.appendingPathComponent("meals")
or
static let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
static let archiveURL = documentsDirectory.appendingPathComponent("meals")
There is documentation for Foundation classes, structs, etc. in your Xcode installation which answers your question. Anyway, your line translates to:
static let ArchiveURL = DocumentsDirectory.appendingPathComponent("meals")
although the Swift coding convention is to use lower camel case for property/variable/constant/method/function names to make your code more comprehensible:
static let archiveURL = documentsDirectory.appendingPathComponent("meals")
If documentsDirectory is a NSURL, then archiveURL is a URL?.
If documentsDirectory is a URL, then archiveURL is a URL.
Here’s a neat trick: if you put code like this into a Swift 3 project, Xcode will give you fix-it suggestions with the new name. For example, for the following:
func foo() {
let DocumentsDirectory: URL! = nil
let ArchiveURL = DocumentsDirectory.URLByAppendingPathComponent("meals")
}
You get two fix-its. The first is:
did you mean 'appendingPathComponent'?
public func appendingPathComponent(_ pathComponent: String, isDirectory: Bool) -> URL
The second is:
did you mean 'appendingPathComponent'?
public func appendingPathComponent(_ pathComponent: String) -> URL
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
nah still not workin'... I translated
static let DocumentsDirectory = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains : .userDomainMask).first!
static let ArchiveURL = DocumentsDirectory.URLByAppendingPathComponent("meals")
to
static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in : .userDomainMask).first!
static let archiveURL = documentsDirectory.appendingPathComponent("meals")
but still not working... gives me the "Value of type URL has no member 'AppendingPathComponent'"
I'm sure you really wrote
static let archiveURL = documentsDirectory.AppendingPathComponent("meals")
instead of
static let archiveURL = documentsDirectory.appendingPathComponent("meals")
Try copying and pasting the following code into your class or struct:
static let documentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
static let archiveURL = documentsDirectory.appendingPathComponent("meals")
or
static let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
static let archiveURL = documentsDirectory.appendingPathComponent("meals")
Thanks man, you were right.
You're welcome 🙂