桥接 'NSNumber' 到 'Int' 警告
Bridging 'NSNumber' to 'Int' warning
这个警告有什么我应该关注的吗?
如果是这样,解决方案是什么?
这是我的职能:
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
}
}
}
我正在使用具有四个不同段的分段控件并使用 firebase 提取数据。
我的个人规则是始终零警告。
安全总比后悔好。
contact
是 Optional
吗?如果是这样...
您可以使用 Optional Binding:
if let contactInt = userSFOList[selectRow].contact as? Int {
destination.contact = contactInt
}
destination.contact = userSFOList[selectedRow].contact.intValue ?? <Your default Int here>
你也可以像@Kamil.S指出的那样使用guard
,比如:
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
这个警告有什么我应该关注的吗?
如果是这样,解决方案是什么? 这是我的职能:
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
}
}
}
我正在使用具有四个不同段的分段控件并使用 firebase 提取数据。
我的个人规则是始终零警告。
安全总比后悔好。
contact
是 Optional
吗?如果是这样...
您可以使用 Optional Binding:
if let contactInt = userSFOList[selectRow].contact as? Int {
destination.contact = contactInt
}
destination.contact = userSFOList[selectedRow].contact.intValue ?? <Your default Int here>
你也可以像@Kamil.S指出的那样使用guard
,比如:
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