ios – Swift 3 Xcode 8中的FileManager和urlsForDirectory错误

前端之家收集整理的这篇文章主要介绍了ios – Swift 3 Xcode 8中的FileManager和urlsForDirectory错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚从beta 3进入了 Xcode 8 beta 4,但出于任何原因我得到的这个错误没有错误或直到测试版4发出.这里是错误“类型’FileManager’的值没有成员’urlsForDirectory’ “

我的代码

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)

“”FileManager’类型的值没有成员’urlsForDirectory’”

解决方法

您只需将其更改为网址(对于:),如下所示:
let documentDirectory = FileManager.default.urls(for: .documentDirectory,in: .userDomainMask).first!

猜你在找的iOS相关文章