0

I just converted my project to Swift 3 and I got an error to directory.path row:

Error: Value of type 'String' has no member 'stringByAppendingPathComponent'.

I've already tried let realmPath = (directory as NSString).stringByAppendingPathComponent instead, I have got the following error:

Cannot convert value of type 'URL' to type 'NSString' in coercion.

override func awake(withContext context: Any?) {
    super.awake(withContext: context)

    let directory: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.RazvanJulian.app")!
    let realmPath = directory.path.stringByAppendingPathComponent("db.realm") /* ERROR */

    RLMRealm.setDefaultRealmPath(realmPath)
    realmToken = RLMRealm.default().addNotificationBlock { note, realm in
        self.reloadTableData()
    }
    reloadTableData()
}

Please check it and let me know.

Thank you in advance!

sabari vasagan
  • 404
  • 5
  • 18
Razvan Julian
  • 59
  • 3
  • 14

1 Answers1

0

stringByAppendingPathComponent became appendingPathComponent in Swift 3. Try this:

directory.appendingPathComponent("component")
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
tai do
  • 124
  • 6