Last active
April 21, 2019 21:36
-
-
Save Rashidium/ef5b37394d88e8c81c8f13c681c1fdc5 to your computer and use it in GitHub Desktop.
Generic Response Decodable with T type.
This file contains 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
import Foundation | |
struct PanpaResponse<T>: Decodable where T: Decodable { | |
private var statusInt: Int? | |
var status: Status { | |
if statusInt == 1 || statusInt == 0 { | |
return .success | |
} | |
return .failed | |
} | |
private var messageString: String? | |
var message: String { | |
if let messageString = messageString { | |
return messageString | |
} else { | |
return "error_generic".localized | |
} | |
} | |
private(set) var data: T? | |
enum CodingKeys: String, CodingKey { | |
case statusInt = "status" | |
case messageString = "message" | |
case data = "data" | |
} | |
init() { | |
self.statusInt = -1 | |
self.messageString = "error_generic".localized | |
self.data = nil | |
} | |
enum Status { | |
case success | |
case failed | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment