aVariable =?? newValue performs the value assignment if newValue is non-nil (like ??= but prefers the newValue over the aVariable):
If newValue is nil, does nothing.
If newValue is non-nil, does the assignment: aVariable = newValue
If aVariable & newValue are both non-nil, still does the assignment.
aVariable =?? newValue
is equivalent to:
// roughly:
aVariable = newValue ?? aVariable
// precisely:
if newValue != nil { aVariable = newValue }
// or
if let newValue = newValue { aVariable = newValue }
Build Overlays
The master branch is Swift 5.x, and build overlays (the minimal changeset to the Package.swift, xcodeproj, and other build files) of the current library version are available on the swift-4.2, swift-4, and swift-3 branches. (Note: I don’t check that these are built as often as I used to when Swift 4.2 or 4.0 were the latest versions, but their changes haved worked and I’ve merged new library versions into them since then.)
NilCoalescingAssignmentOperators
NilCoalescingAssignmentOperators is Swift micro-library that provides two nil-coalescing/assignment-combo operators:
??=aVariable ??= newValueperforms the value assignment ifaVariableis nil (like Ruby’s||=operator):aVariableis non-nil, does nothing.aVariableis nil butnewValueis non-nil, does the assignment:aVariable = newValueaVariable&newValueare both nil, does nothing.is equivalent to:
=??aVariable =?? newValueperforms the value assignment ifnewValueis non-nil (like??=but prefers thenewValueover theaVariable):newValueis nil, does nothing.newValueis non-nil, does the assignment:aVariable = newValueaVariable&newValueare both non-nil, still does the assignment.is equivalent to:
Build Overlays
The master branch is Swift 5.x, and build overlays (the minimal changeset to the Package.swift, xcodeproj, and other build files) of the current library version are available on the swift-4.2, swift-4, and swift-3 branches. (Note: I don’t check that these are built as often as I used to when Swift 4.2 or 4.0 were the latest versions, but their changes haved worked and I’ve merged new library versions into them since then.)