$30 off During Our Annual Pro Sale. View details »

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. Operators in Swift Sash Zats - zats.io - @zats -

    September 8, Tel Aviv
  2. Operator?

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

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

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

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

    precedence • Implement function • Arguments define applicability • Overrides operators within the module • inout for assignment
  7. Guidelines • Clarity • Simplicity • Analogy • Order of

    execution
  8. Demo

  9. 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
  10. Conclusion To get around clashes when operator overloading, we should

    all just give them a three letter prefix — @danielctull