DangerousError = -999 } func awesome(error: NSErrorPointer) -> String? { error.memory = NSError(domain: MyError.domain, code: MyError.DangerousError.rawValue, userInfo: nil) return nil } func test() { var error: NSError? let result = awesome(&error) if let r = result { print(r) } if let e = error { print(e) } } test() Swift 1.x
enum State { case Sitting case Sleeping case Walking } var state: State = .Sitting mutating func walk() throws { guard state != .Sleeping else { throw Error.Sleeping } state = .Walking } } guard