Created
November 8, 2015 14:34
-
-
Save YusukeHosonuma/10dbc31d181f9b105246 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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