NilCoalescingAssignmentOperators

0.3.4

Combo Operators ??= and =?? (a Swift µ-Library)
capnslipp/NilCoalescingAssignmentOperators

What's New

0.3.4

2023-05-13T02:31:37Z

Minor:

  • Made README clearer still (hopefully) by replacing lhsaVariable and rhsnewValue and a few other rewrites. a38507b
  • Added to podspec a readme entry pointing to raw source of the README.md on GitHub b89e95a

Full Changelog: 0.3.3...0.3.4

NilCoalescingAssignmentOperators

NilCoalescingAssignmentOperators is Swift micro-library that provides two nil-coalescing/assignment-combo operators:

??=

aVariable ??= newValue performs the value assignment if aVariable is nil (like Ruby's ||= operator):

  1. If aVariable is non-nil, does nothing.
  2. If aVariable is nil but newValue is non-nil, does the assignment: aVariable = newValue
  3. If aVariable & newValue are both nil, does nothing.
aVariable ??= newValue

is equivalent to:

// roughly:
aVariable = aVariable ?? newValue

// precisely:
if aVariable == nil { aVariable = newValue }

=??

aVariable =?? newValue performs the value assignment if newValue is non-nil (like ??= but prefers the newValue over the aVariable):

  1. If newValue is nil, does nothing.
  2. If newValue is non-nil, does the assignment: aVariable = newValue
  3. 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.)

Description

  • Swift Tools 5.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Mar 18 2024 07:16:56 GMT-0900 (Hawaii-Aleutian Daylight Time)