2017-07-27 48 views
0

我只是將我的項目斯威夫特3,我得到了一個錯誤directory.path行:值類型「字符串」沒有成員「stringByAppendingPathComponent」

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

我已經嘗試過let realmPath = (directory as NSString).stringByAppendingPathComponent相反,我有以下錯誤:

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() 
} 

請檢查一下,讓我知道。

預先感謝您!

+0

看到這個https://stackoverflow.com/questions/35541747/create-directory-in-app-group-container-swift –

+0

你是強制爲具有'stringByAppendingPathComponent'的'NSString',因此不要施放它 – Jack

回答

0

stringByAppendingPathComponent斯威夫特3.成爲appendingPathComponent試試這個:

directory.appendingPathComponent("component") 
相關問題