A More Swifty Way to Check an Optional for a Nil Value

Is there a use case for this? I'm having a hard time imagining it.

Assigning only non-nil values, that I've seen to be useful.

infix operator =?: AssignmentPrecedence

public extension Optional {
  static func =? (optional0: inout Self, optional1: Self) {
    if let optional1 {
      optional0 = optional1
    }
  }

  static func =? (wrapped: inout Wrapped, optional: Self) {
    if let optional {
      wrapped = optional
    }
  }
}
2 Likes