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'
"
You just need to change it to urls(for:)
as follow:
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With