Skip to content

Instantly share code, notes, and snippets.

@gurgeous
Last active August 29, 2015 14:09
Show Gist options
  • Save gurgeous/3736b80430b71d13293f to your computer and use it in GitHub Desktop.
Save gurgeous/3736b80430b71d13293f to your computer and use it in GitHub Desktop.
Swift syntactic sugar wishlist

Regex literals and operators

let re = /regex/
if "xyz" =~ /regex/ {  }

Optionals as conditionals

let maybe: String?
if maybe != nil { } // works
if maybe { } // should work :)
if !maybe { } // this too

Array <<

var array = [ Int ]()
array << 123

NSDate math

let x = NSDate()
let tomorrow = x + 1
let nextMonth = x << 1

This is your big chance!

The String API should be much bigger. At the very least we need Int ranges and .length. Ditto for Array and Dictionary.

If you don't put these into stdlib we'll be stuck with millions of buggy libraries as everyone tries to implement this themselves. See:

Numeric promotion (pretty please?)

let x = 3
let y = 0.5
let z = x + y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment