Skip to content

Instantly share code, notes, and snippets.

@YusukeHosonuma
Created November 8, 2015 14:34
Show Gist options
  • Save YusukeHosonuma/10dbc31d181f9b105246 to your computer and use it in GitHub Desktop.
Save YusukeHosonuma/10dbc31d181f9b105246 to your computer and use it in GitHub Desktop.
//
// SampleAPI.swift
// APISample
//
// Created by Yusuke on 11/8/15.
// Copyright © 2015 Yusuke. All rights reserved.
//
import Foundation
class SampleAPI {
enum APIResult {
case Success(result: APIResultSuccess)
case Error(error: ErrorResult)
struct ErrorResult {
let code: Int
let message: String
}
}
struct APIResultSuccess {
let taskList: [String]
}
func getTaskList(isSuccess: Bool, handler: (APIResult -> Void)) {
// connecting...
// success
if isSuccess {
let taskList = ["Apple", "Orange", "Banana"]
let result = APIResultSuccess(taskList: taskList)
handler(.Success(result: result))
} else {
let error = APIResult.ErrorResult(code: 404, message: "not found")
handler(.Error(error: error))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment