Custom operators in swift

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
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

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

10 slides
  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

More Decks by Sash Zats

Other Decks in Technology