6 Replies
      Latest reply: Feb 6, 2017 1:03 PM by goldsdad RSS
      ShahinGhani Level 1 Level 1 (0 points)

        what is

        static let ArchiveURL = DocumentsDirectory.URLByAppendingPathComponent("meals")
        
        

        renamed to in Swift 3?

        • Re: ArchiveURL
          goldsdad Level 4 Level 4 (580 points)

          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.

            • Re: ArchiveURL
              ShahinGhani Level 1 Level 1 (0 points)

              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'"

                • Re: ArchiveURL
                  goldsdad Level 4 Level 4 (580 points)

                  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")
                  
              • Re: ArchiveURL
                eskimo Apple Staff Apple Staff (7,530 points)

                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"