mergesort mergesort - 2 months ago 10
iOS Question

How to compare Obj C enum in Swift?

I am using FreeStreamer in Swift and am trying to set the

onStateChange
block.

audioStream.onStateChange = { (state) in
if state == kFsAudioStreamBuffering {
//blah
}
}


I am getting this error:

Binary operator '==' cannot be applied to operands of type '(FSAudioStreamState)' and 'FSAudioStreamState'


Edit: Still the same error without the parentheses around state in the block params

EDIT: As a temporary fix,
state.value == kFsAudioStreamBuffering.value
works

Answer

try putting a dot (.) before kFsAudioStreamBuffering something like this:

if state == .kFsAudioStreamBuffering {
    //blah
}

UPDATE: Try this instead

audioStream.onStateChange = { state in
    if state.value == kFsAudioStreamBuffering.value {
        //blah
    }
}