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

废话没有直接代码

<pre>
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 "";
    }

}
</pre>

使用就😄更简单了,在网络请求的返回码后
<pre>
let rescode = ret.objectForKey("rescode") as! String
Toast.show(rescode, ti: 2)
</pre>

864DE113-93E2-4CA7-AC34-1D8F67CED622.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,367评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,711评论 4 61
  • 刚看到罗辑思维的一篇文章 牢牢记住了很深意的一句话:灰色认知,黑白决策。 这当下,有多少人死在了不懂这句话上。 不...
    四小姐的春天阅读 5,324评论 0 1
  • 紅豆曲一生所愛 迷津无痕是宿命。苦海翻起的爱恨,吹不散的眉弯。相亲竟不可接近,任深情独向寂寞。缘起如流不断的绿水悠...
    古小凤阅读 2,944评论 0 0
  • 焦作市首家文化型养老典范,活力养老住区的引领者。创建文化、体育、医疗一体化新型养老模式。高质量服务,低价格收费。这...
    xiaohichong阅读 2,695评论 0 0

友情链接更多精彩内容