0

I'm finding my way around Xcode and tried to build a basic live transcription app using the guidance on Apple's developer website (link)

The following line throws the error shown below:

guard let inputNode = audioEngine.inputNode else { fatalError("Audio engine has no input node") }

"Initializer for conditional binding must have Optional type, not AVAudioInputNode"

I've checked every stackoverflow post with similar errors and nothing has worked. I even downloaded the project from Apple from the above link and their code is error-free. I copied the code from their project into mine in case I had a silly mistake somewhere but in my project the exact same code always throws the exception.

I am using Xcode 9.2 and I'm developing for iOS 11.

Thanks!

Isma
  • 14,604
  • 5
  • 37
  • 51
Justin 915
  • 11
  • 2

1 Answers1

0

The guard statement in your case is redundant. inputNode is not an optional so it can never hold nil value. So guarding for that is redundant, hence the error message.

You can omit the guard statement and its else block replacing it with:

let inputNode = audioEngine.inputNode
giorashc
  • 13,691
  • 3
  • 35
  • 71
  • Makes sense, but how do I fix it? If I remove "guard" and leave it as "let..." Xcode throws errors over the rest of the code? Thanks! – Justin 915 Dec 26 '17 at 16:35
  • @Justin915 I edited my answer. you can use let statement (but without the else block as it makes no sense and is an incorrect syntax without the guard keyword) – giorashc Dec 26 '17 at 16:51