Instantly share code, notes, and snippets.


Try writing this with both an option field and a hanging animation closure, with no completion...

        UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: { 
        }, completion: nil)

I should beable to do this


Example Enums:

enum SessionChannel: Int {
    case NeedsAuthentication = 0
    case VerifiedUser = 1

enum SessionEvent {
View if let
infix operator ?= {  precedence 90 }

func ?= <T> (inout f: T, optional:T?){
    let _  = optional.flatMap{f = $0}

Usage looks like: ?= json["name"]?.string
View gist:efe3b136b3e59765c667
private func comparableAttributes<T, U:Equatable>(first f:T, second s:T)->(T->U) -> U?{
    return { trans in
        let x = trans(f)
        let y = trans(s)
        return (x == y) ? nil : x

If i do this it doesnt work...

View gist:308603afa65cbbfba07c

###Subject: isEqual to replace == Equatable Requirement

Hi all,

I would like to propose changing the Equatable protocol to use isEqual(to:Self) -> Bool, defined inside of a type to replace the currently used operator == function, which is defined outside of the type.


  1. Having the conforming function defined inside of the type is more intuitive, since in general functions required for conformance are defined within the type. It feels like an unnecesary detail for learners of Swift to have to stumble through.
View gist:304b0da0548752dd4230
let arr = [1,2,3,4]
func & <T>(lhs:Array<T>,rhs:[Int]) -> T?{
guard let index = rhs.first else{
print("no index!")
return nil
if index < 0{
print("negative index")
View gist:619dc749a529e19412d1
enum ListError: ErrorType {
case Empty
case Unknown
extension CollectionType {
typealias Elem = Self.Generator.Element
View gist:30f4ec3cb9806223b6f4
<>, both not included in range,
<=>, both included
<==, left not included,
==> right not included
infix operator <> {}
infix operator <=> {}
infix operator ==> {}
infix operator <== {}
View gist:98c5db1f4125ce27309d
func ~= <T:Comparable>(lhs:T,rhs:(T,T)) -> Bool{
if lhs < rhs.0{
return false
if lhs > rhs.1{
return false
View gist:d2bbd7a070f0b98fb68f
extension Int {
/// Construct an instance that approximates `other`.
public init(_ other: Float)
/// Construct an instance that approximates `other`.
public init(_ other: Double)
/// Construct an instance that approximates `other`.
public init(_ other: Float80)