2015-10-16 68 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