降低项目耦合性之服务器返回码的封装

废话没有直接代码


import Foundation

class Toast: NSObject{
static func show( ti: NSTimeInterval,rescode :String! ){
let msg = self. getMsg(rescode)
let alert = UIAlertView()
alert.message = msg
alert.show()
NSTimer.scheduledTimerWithTimeInterval(ti, target: self, selector: "dismissUIAlertView:", userInfo: alert, repeats: false)
}

static func dismissUIAlertView(t: NSTimer){
    let alert = t.userInfo as! UIAlertView
    alert.dismissWithClickedButtonIndex(-10, animated: true)
}

func getMsg(rescode : String!) -> String{

    if rescode == "10000" {
        //登录成功不做处理
        return "";
    }else if rescode == "20501" {
        
        
        return "邮箱不存在"
    }else if rescode == "20502" {
        
        return "手机号码不存在"
    }else if rescode == "20601" {
        
        
        return"邮箱已存在"
    }
    else if rescode == "20602" {
        return"手机号已存在"
    }
    else if rescode == "20300"{
        return"验证码错误"
    }else{
    return "";
    }

}

使用就更简单了,在网络请求的返回码后


let rescode = ret.objectForKey("rescode") as! String
Toast.show(rescode, ti: 2)

降低项目耦合性之服务器返回码的封装_第1张图片
864DE113-93E2-4CA7-AC34-1D8F67CED622.png

你可能感兴趣的:(降低项目耦合性之服务器返回码的封装)