Aron Aron - 1 month ago 4x
Swift Question

EZAudio stopfetching audio

When I call the function

from EZAudio, my app crashes.

var microphone: EZMicrophone!

func didMove(to view: SKView){

* setup all dependencys for the fft analysis

//setup audio session
session = AVAudioSession.sharedInstance()
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try session.setActive(true)
print("Audio Session setup Fails")

//create a mic instance
microphone = EZMicrophone(delegate: self)


func stopMic(){

I get this error:

xyz-abv[435:35687] fatal error: unexpectedly found nil while unwrapping an Optional value

But I don't know which optional it mean.


I think it should be:

func stopMic(){
    if let _ = microphone {

Explanation: The reason is you move from one view(where microphone is used) to another view without intializing it. And when you call the stop method from second view controller, it causes error, because microphone is NIL.