Skip to content

Instantly share code, notes, and snippets.

@lazyvar
Created May 19, 2022 15:25
Show Gist options
  • Save lazyvar/0c59567104cb9875dd7135bbb8f01ae4 to your computer and use it in GitHub Desktop.
Save lazyvar/0c59567104cb9875dd7135bbb8f01ae4 to your computer and use it in GitHub Desktop.
// Equatable+nil.swift
struct Model: Equatable { }
let model = Model()
print(model == nil) // This compiles and produces a warning
print(model == .none) // This compiles with no warning
@lazyvar
Copy link
Author

lazyvar commented May 19, 2022

I guess synthesized equatable definitions will produce something like this:

struct HandModel {
  static func == (lhs: HandModel, rhs: HandModel) -> Bool {
    return true
  }

  static func == (lhs: HandModel, rhs: HandModel?) -> Bool {
    guard let rhs = rhs else { return false }

    return lhs == rhs
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment