Paste: Swift type checking

Author: jckarter
Mode: text
Date: Mon, 2 Jun 2014 19:58:34
Plain Text |
func foo<T>(x: T) -> Int? {
  switch x {
    case let int as Int:
      return x + 1
    case let str as String:
      return str.toInt().map { $0 + 1 }
    case let doub as Double:
      return Int(doub)
    default:
      return nil
  }
}

New Annotation

Summary:
Author:
Mode:
Body: