Please, you need to change the lines 39 and 67 respectively as below:
39 - try AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: [])
67 - switch AVAudioSession.sharedInstance().recordPermission{
This is the correct implementation. Your current build is wrong and crashes.