簡體   English   中英

將'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
}

或者Nil-Coalescing運算符

destination.contact = userSFOList[selectedRow].contact.intValue ?? <Your default Int here>

你也可以使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM