NilCoalescingAssignmentOperators is Swift micro-library that provides two nil-coalescing/assignment-combo operators:
lhs ??= rhs works like Ruby's ||= operator:
- If
lhsis non-nil, does nothing. - If
lhsis nil butrhsis non-nil, does the assignment:lhs = rhs - If
lhs&rhsare both nil, does nothing.
lhs =?? rhs works similarly, but prefers the rhs over the lhs:
- If
rhsis nil, does nothing. - If
rhsis non-nil, does the assignment:lhs = rhs
- If
lhs&rhsare both non-nil, still does the assignment.