jsdw_ios/QuickLocation/Main/BaseModel/BaseModelNew.swift

113 lines
2.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// BaseModel.swift
// dinoGo
//
// Created by on 2020/5/18.
// Copyright © 2020 Lin. All rights reserved.
//
import Foundation
import ObjectMapper
import SwiftyJSON
var transformInt: (Any?) -> Int? = { value in
switch value {
case let value as String:
return Int(value)
case let value as Int:
return value
case let value as Double:
return Int(value)
default:
return nil
}
}
var transformStr: (Any?) -> String? = { value in
switch value {
case let value as String:
return value
case let value as Int:
return String(value)
case let value as Double:
return String(value)
default:
return nil
}
}
var transformJSON: (Any?) -> JSON? = { value in
if let jsonString = value as? String {
return JSON(jsonString)
}
return nil
}
var transformJsonStr: (Any?) -> String? = { value in
if let json = value as? JSON {
return json.string
}
return nil
}
/// String >> Int
let kStrTransformInt = TransformOf<Int, Any>(fromJSON: transformInt,
toJSON: transformStr)
/// Int >> String
let kIntTransformStr = TransformOf<String, Any>(fromJSON: transformStr,
toJSON: transformInt)
/// StringtoJSON URL Int
let kFlexString = TransformOf<String, Any>(fromJSON: transformStr, toJSON: { $0 })
/// JsonString >> Json
let kJsonStrTransformJson = TransformOf<JSON, Any>(fromJSON: transformJSON,
toJSON: transformJsonStr)
protocol BaseModelProtocol: Mappable {
var status: Bool? { get }
var code: String? { get }
var status_code: Int? { get }
var message: String? { get }
}
extension BaseModelProtocol {
var status: Bool? { return nil }
var code: String? { return nil}
var status_code: Int? { return nil }
var isSuccess: Bool {
// if let status = status, status == true {
// if let code = code, code == GatewayStatusCodeOld.success.rawValue {
// return true
// }
//
// }
// API
if let status_code = status_code, status_code == GatewayStatusCode.success.rawValue {
return true
}
return false
}
}
enum BoolType: String {
case `true` = "Y"
case `false` = "N"
var boolValue: Bool {
switch self {
case .true:
return true
case .false:
return false
}
}
}