Search code examples
swiftswift3assertionsconditional-operator

Concise Swift assertion for Bool? || Bool?


Can I formulate a concise expression in Swift for asserting that the activity indicator of one of two view controllers is animating. The expression may assume that either vc1 or vc2 is distinct from nil.

The following does not quite work, presumably because it is of the form Bool? || Bool? instead of Bool || Bool:

assert(vc1?.activityIndicator.isAnimating ||
       v22?.activityIndicator.isAnimating)

Solution

  • == still works for optionals, so you could do something like this:

    assert(vc1?.activityIndicator.isAnimating == true ||
           v22?.activityIndicator.isAnimating == true)