继承BaseViewController实现Dark模式
struct MyMoyaManager {
//MARK: - 通用请求
static func AllRequest< T : TargetType > ( controller: UIViewController , _ target: T , success successCallback: @escaping ( BaseResponse ) -> Void , failed failedCallback: @escaping ( BaseResponse ? ) -> Void ) {
let provider = MoyaProvider < T > ( endpointClosure: endpointMapping , requestClosure: requestClosure, manager: moyaManager ( ) , plugins: [ RequestAlertPlugin ( viewController: controller) ] )
provider. request ( target) { ( event) in
switch event {
case let . success( response) :
do {
let data = try response. mapJSON ( ) as! [ String : Any ]
if let u = BaseResponse ( JSON: data) {
successCallback ( u)
log. info ( u)
} else {
controller. ShowTip ( Title: " 解析失败 " )
}
log. error ( data)
} catch {
//可不做处理
failedCallback ( nil )
controller. ShowTip ( Title: " 请求失败,解析异常 " )
}
break
case let . failure( error) :
failedCallback ( nil )
log. error ( error)
break
}
}
}
}
extension KeychainManager {
struct User : KeychainManagerSettable {
enum defaultKeys : String , CaseIterable {
case 手机号
case 密码
case 公钥
case 私钥
case token
case userid
}
}
}
protocol KeychainManagerSettable {
associatedtype defaultKeys : RawRepresentable
}
extension KeychainManagerSettable where defaultKeys. RawValue == String {
// TODO: 存储数据
static func SaveByIdentifier( data: Any , forKey key : defaultKeys ) -> Bool {
let akey = key. rawValue
// 获取存储数据的条件
return KeychainManager . keyChainSaveData ( data: data, withIdentifier: akey)
}
// TODO: 更新数据
static func UpdataByIdentifier( data: Any , forKey key : defaultKeys ) -> Bool {
let akey = key. rawValue
return KeychainManager . keyChainUpdata ( data: data, withIdentifier: akey)
}
// TODO: 获取数据
static func ReadDataByIdentifier( forKey key : defaultKeys ) -> Any {
let akey = key. rawValue
return KeychainManager . keyChainReadData ( identifier: akey)
}
// TODO: 删除数据
static func DeleteByIdentifier( forKey key : defaultKeys ) -> Void {
let akey = key. rawValue
KeychainManager . keyChianDelete ( identifier: akey)
}
}
//保存数据 Any
if KeychainManager . User. SaveByIdentifier ( data: " 1398784645 " , forKey: . 手机号) {
//保存成功
} else {
//保存失败
}
//获取数据
let phone = KeychainManager . User. ReadDataByIdentifier ( forKey: . 手机号) as? String
//删除数据
KeychainManager . User. DeleteByIdentifier ( forKey: . 手机号)
//保存数据
UserDefaults . User. set ( value: " 1355024547 " , forKey: . 手机号)
//获取数据
let phone = UserDefaults . User. getvalue ( forKey: . 手机号) as? String