[英]Bridging 'NSNumber' to 'Int' warning
Is this warning anything that I should be concerned about? 这是警告我应该关注的吗?
If so what would be a solution? 如果是这样,什么是解决方案? this is my function :
这是我的功能:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? ProfileViewController{
let cell = sender as! UITableViewCell
let selectedRow = myTableView.indexPath(for: cell)!.row
switch (mySegmentedControl.selectedSegmentIndex){
case 0:
destination.nameVar = userSFList[selectedRow].name!
destination.imageOneURL = userSFList[selectedRow].image!
destination.bioVar = userSFList[selectedRow].bio!
if let image2 = userSFList[selectedRow].imageTwo {
destination.imageTwoUrl = image2 }
if let contactInt = userSFList[selectedRow].contact as? Int {
destination.contact = contactInt
}
break
case 1:
destination.nameVar = userEBList[selectedRow].name!
destination.imageOneURL = userEBList[selectedRow].image!
destination.imageTwoUrl = userEBList[selectedRow].imageTwo!
if let contactInt = userEBList[selectedRow].contact as? Int {
destination.contact = contactInt
}
break
case 2:
destination.nameVar = userSFOList[selectedRow].name!
destination.imageOneURL = userSFOList[selectedRow].image!
if let contactInt = userSFOList[selectedRow].contact as? Int {
destination.contact = contactInt
}
break
case 3:
destination.nameVar = userSJList[selectedRow].name!
destination.imageOneURL = userSJList[selectedRow].image!
if let contactInt = userSJList[selectedRow].contact as? Int {
destination.contact = contactInt
}
break
default:
break
}
}
} }
I am using a segmented control with four different segments and pulling the data using firebase. 我正在使用具有四个不同段的分段控件并使用firebase提取数据。
My personal rule is always zero warnings . 我的个人规则始终是零警告 。
Better safe than sorry. 比抱歉更安全。
Is contact
an Optional
? contact
是否Optional
? If so... 如果是这样...
You could use Optional Binding : 您可以使用Optional Binding :
if let contactInt = userSFOList[selectRow].contact as? Int {
destination.contact = contactInt
}
Or the Nil-Coalescing Operator : 或者Nil-Coalescing运算符 :
destination.contact = userSFOList[selectedRow].contact.intValue ?? <Your default Int here>
You could also use guard
as pointed out by @Kamil.S, like: 你也可以使用
guard
由@ Kamil.S指出,如:
guard let nameVar = userSFOList[selectedRow].name,
let imageVar = userSFOList[selectedRow].image,
let contactVar = contact as? Int else {
// Conditions were failed. `return` or `throw`.
}
destination.nameVar = nameVar
destination.imageOneURL = imageVar
destination.contact = contactVar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.