shallowThought shallowThought - 23 days ago 14
iOS Question

How to suppress compiler warning

this code:

guard let isNotNil = anOptional
else {
#if DEBUG
fatalError()
#endif
return false
}


gives a compiler warning n debug mode on
return false
:


Will never been executed


Which is right but by intention.

How can I suppress this warning?

Answer

With an else statement:

guard let isNotNil = anOptional
        else {
            #if DEBUG
                fatalError()
            #else
                return false
            #endif

}

You can also go to the project or the target build settings and disable the warning for unreachable code.

Comments