swift - 我只想通过比较基本上通过webapi从数据库获得的角色名称来移动到另一个屏幕......有什么办法吗?
问题描述
这是登录按钮操作代码......我真正想要的是如果我点击登录按钮,如果它的(代理)<--(它的 r_name)那么它应该移动到下一个屏幕......响应变量包含来自数据库的所有数据我只想从该响应变量中获取 r_name 就是这样
@IBAction func btnLogin(_ sender: Any) {
//normally it moves to the next screen by applying below code but I want to compare roles name if e.g role name="agent" then move to another screen
let response = mm.alluser(phoneNo: txtPhoneNumber.text!, Password: txtPassword.text!)
if response.count ?? 0 > 0
{
let next : tabViewController = self.storyboard?.instantiateViewController(withIdentifier: "tabViewController") as! tabViewController
self.navigationController?.pushViewController(next, animated: true)
showalertforloginsuccess()
print("Login Successfull")
}else
{
showalertforloginfail()
print("Not Login")
}
}
//这里是一个包含角色属性的类userModel
public class UserModel:Codable
{
public var u_id: Int = 0
public var u_name: String?=""
public var phoneNumber: String?=""
public var address: String? = ""
public var password: String? = ""
public var r_id: Int? = 0
public var r_name: String? = ""
}
//用户管理器类通过名为(alluser)的函数与web api交互
class Usersmanager
{
var apiwrapper=APIWrapper()
var decoder=JSONDecoder()
var encoder=JSONEncoder()
var Message=""
public func alluser(phoneNo: String, Password : String)->[UserModel]
{
var users:[UserModel]=[]
let result=apiwrapper.getMethodCall(controllerName: "user", actionName: "Userlogin?phoneNo=\(phoneNo)&Password=\(Password)")
if result.ResponseCode==200{
guard let data=result.ResponseData
else{
Message=result.ResponseMessage
return users
}
//data is now valid
users = try! decoder.decode([UserModel].self,from: data)
}
else {
Message=result.ResponseMessage
}
return users
}
}
解决方案
推荐阅读
- python - Tensorflow 2.0中的多输入CNN没有做任何事情
- layout - 如何将最近查看的产品放在页脚顶部
- html - 如何防止我的通用 * { ... } 样式覆盖父标签
- google-chrome - 后台模式下的 PWA 行为
- html - 打印时如何在每个页面上添加徽标
- dictionary - 用于在地图上插入和总查找的 Monad 转换器?
- java - 将索引列添加到 apache spark 数据集
使用java
- postgresql - 在 postgres 上使用 `random_page_cost` 优化最近的事件搜索和缓存使用
- python-3.x - 如果值存在,则数据框过滤器,否则返回所有
- android - 使用 FB 和 google 移动广告 sdk 时,一个 dex 文件中的字段引用过多