Skip to content

Instantly share code, notes, and snippets.

@Rashidium
Last active April 21, 2019 21:36
Show Gist options
  • Save Rashidium/ef5b37394d88e8c81c8f13c681c1fdc5 to your computer and use it in GitHub Desktop.
Save Rashidium/ef5b37394d88e8c81c8f13c681c1fdc5 to your computer and use it in GitHub Desktop.
Generic Response Decodable with T type.
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