SwiftUserManager

MIT 许可协议
Swift
iOS

1 张图片

作者

描述

使用 Swift 3.0 编写的用户管理器,让您免受保存活动用户会话的烦恼。

** 调用 API 并将 JSON 传递给 MOProfile 以创建模型,然后调用 UserManager.setCurrentUser(model)

let profileFromServer = [
    "firstName" : "Zeeshan",
    "userName" : "xeieshan",
    "lastName" : "Haider",
    "id" : 1,
    "email" : "[email protected]"
    ] as [String : Any]
let profileModel : MOProfile = MOProfile(profileFromServer as Dictionary<String, AnyObject>)
UserManager.setCurrentUser(newCurrentUser: profileModel)

**Now you can use this**
debugPrint((UserManager.currentUser?.firstName)! as String)

**To logout simply call**
UserManager.logOutUserAndClearToken()

**If you want to see if your user is logged (for autologin)**
 if UserManager.currentUser != nil {
 // Take to App
 } else {
 // Take to Login
 }

标签