2015-09-19 24 views
0

嗯通常Swift升級需要重寫。我可敬的路徑命令不再起作用說:「stringByAppendingPathCompnent不可用」stringByAppendingPathCompnent不可用

return NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0].stringByAppendingPathComponent(fileName) 

如果我使用URLByAppendingComponent的指示

return NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0].URLByAppendingPathComponent(fileName) 

據我所知,String類型的值沒有任何成員URLByAppointmentPathComponent

如何我應該着手解決這個問題嗎?

+0

我通過這個問題去之前,我貼我的,不能工作了它是如何回答我的問題。這很可能是我缺乏經驗,但我發現Swift 2.0更改說明錯綜複雜。讚賞, –

+0

將字符串轉換爲NSString。 – Darko

回答

1

取而代之的是你可以試試這個:

return try! NSFileManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true).URLByAppendingPathComponent(fileName).path! 
+0

是的,它的工作原理。 –

+0

高興地幫助你.. :) –