Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Custom operators in swift

Sash Zats
November 23, 2014

Custom operators in swift

Abusing custom operators in Swift.
You can find the sample code on github https://github.com/zats/Presentations/tree/master/Operators%20In%20Swift/Sample%20Project

Sash Zats

November 23, 2014
Tweet

More Decks by Sash Zats

Other Decks in Technology

Transcript

  1. Operator! Language constructs which behave generally like functions, but differ

    syntactically or semantically from usual functions — Wikipedia
  2. …in Swift? An operator is a special symbol or phrase

    that you use to check, change, or combine values. — The Swift Programing Language
  3. …in Swift! • Assignment, logic, math, binary, overflow, range; •

    Unary, binary, ternary; • Prefix, infix, postfix; • Precedence • Associativity
  4. Overloading & custom operators • Define operator • Associativity, assignment,

    precedence • Implement function • Arguments define applicability • Overrides operators within the module • inout for assignment
  5. Shortcoming • Why bother? What's wrong with functions? • No

    unicode in operator names. Where is my image.!? • No way to create ternary operators • No scopes: Cartography - auto layout done with custom operators
  6. Conclusion To get around clashes when operator overloading, we should

    all just give them a three letter prefix — @danielctull