Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileManager and urlsForDirectory Error in Swift 3 Xcode 8

Tags:

ios

swift

swift3

I just went to Xcode 8 beta 4 from beta 3 but for what ever reason I am getting this error that has worked with no errors or issued until beta 4. here is the error" Value of type 'FileManager' has no member 'urlsForDirectory' "

my code:

 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");

                    }

                }
            })
        }

    }

BUT the only part is this line:

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

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

like image 390
iOS Newbie Avatar asked Aug 03 '16 22:08

iOS Newbie


1 Answers

You just need to change it to urls(for:) as follow:

let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
like image 136
Leo Dabus Avatar answered Sep 22 '22 12:09

Leo Dabus