Bridging NSNumber to Int Warning

Is this warning something that bothers me?

warning

If so, what will be the 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 use a segmented control with four different segments and pulling data with firebase.

+4
source share
1 answer

My personal rule is always with zero warnings .
Better than sorry.

Is contacta Optional? If so...

You can use optional binding :

if let contactInt = userSFOList[selectRow].contact as? Int {
  destination.contact = contactInt
}

Or the Nil-Coalescing statement :

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
+4

Source: https://habr.com/ru/post/1674349/


All Articles