2015-10-16 67 views
0

我已經更新的Xcode 7個我所有的應用程序,從迅疾迅速2.0轉換後,得到的錯誤,一些研究之後,我能夠手動修復它們。雨燕2.0 - stringByAppendingPathComponent錯誤轉換

不過,我有「stringByAppendingPathComponent」我解決不了錯誤。似乎swift 2.0刪除了這個方法。

連接圖爲我平鋪有關錯誤。

enter image description here

任何想法如何解決這個問題呢?

func loadNotes(){ 


     let plistPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) as NSArray 
     let DocumentsDirectory = plistPath[0] as! String 
     let path = DocumentsDirectory.stringByAppendingPathComponent("notes.plist") 
     let fileManager = NSFileManager.defaultManager() 

     if (!fileManager.fileExistsAtPath(path)) { 

      if let bundlePath = NSBundle.mainBundle().pathForResource("notes", ofType: "plist") { 

       let resultDictionary = NSMutableDictionary(contentsOfFile: bundlePath) 
       println("Bundle notes.plist file is --> \(resultDictionary?.description)") 
       fileManager.copyItemAtPath(bundlePath, toPath: path, error: nil) 
       println("copy") 

      } else { 
       println("notes.plist not found") 
      } 


     }else { 
      println("note.plist already exists") 

      //fileManager.removeItemAtPath(path, error: nil) 
     } 

     let resultDictionary = NSMutableDictionary(contentsOfFile: path) 
     println("Loaded notes.plist file is --> \(resultDictionary?.description)") 
     var myDict = NSDictionary(contentsOfFile: path) 

     if let dict = myDict { 
      //load values 

     } else { 

      println("worning ccould not create dictionary from notes.plist, default values will be used") 
     } 

    } 
+0

這是很多雨燕1.2的代碼 - 沒有更多的println – Jeef

+0

嘗試使用轉換爲最新的迅速語法選項 – Jeef

+0

嗨Jeef是我連着1.2 - 我曾嘗試使用轉換爲最新的迅速語法選項,但錯誤沒有改變 – SNos

回答

-1

蘋果希望你所使用的網址,而不是路徑,以便它們使人們在雨燕2.不可用。如果你不想使用NSURL,您可以暫時將其轉換爲NSString代替:

let path = (DocumentsDirectory as NSString).stringByAppendingPathComponent("notes.plist") 
+0

決不將String轉換爲NSString。查看Apple規定的內容。 https://github.com/apple/swift/blob/adc54c8a4d13fbebfeb68244bac401ef2528d6d0/stdlib/public/SDK/Foundation/NSStringAPI.swift#L1345 – Brennan