2016-08-03 84 views
5

我剛剛從測試版3到Xcode 8測試版4,但由於什麼原因我得到這個錯誤,沒有錯誤的工作或發佈,直到測試版4.這裏是錯誤「 Value of type 'FileManager' has no member 'urlsForDirectory'FileManager和urlsForDirectory錯誤在Swift 3 Xcode 8

我的代碼:

func setupRecorder(){ 

     let audioSession:AVAudioSession = AVAudioSession.sharedInstance() 

     //ask for permission 
     if (audioSession.responds(to: #selector(AVAudioSession.requestRecordPermission(_:)))) { 
      AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in 
       if granted { 
        print("Permission Granted\n") 

        //set category and activate recorder session 
        do { 
         //---- 
         let fileManager = FileManager.default 
         let urls = fileManager.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask) 
         //---- 
         let documentDirectory = urls[0] as URL 
         let soundURL = try! documentDirectory.appendingPathComponent("sound.m4a") 

         try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord) 

         try self.soundRecorder = AVAudioRecorder(url: soundURL, settings: self.recordSettings) 

         let micInput = try AVAudioRecorder(url 
         : soundURL, settings: self.recordSettings) 


         self.soundRecorder.prepareToRecord() 
         self.soundRecorder.updateMeters() 



        } catch { 

         print("Error Recording"); 

        } 

       } 
      }) 
     } 

    } 

但唯一的部分是這一行:

   let urls = fileManager.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask) 

'Value of type 'FileManager' has no member 'urlsForDirectory'

回答

7

你只需將其更改爲網址(:)如下:

let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first! 
+1

或FUNC。contentsOfDirectory(以URL:URL,includingPropertiesForKeys鍵:[URLResourceKey]?選擇面膜:FileManager.DirectoryEnumerationOptions = [] )拋出 - > [URL] – Dis3buted

相關問題