can't convert string into int to display on label

import UIKit
class cuenta: UIViewController {

    @IBOutlet weak var displaytotal: UILabel!
    @IBOutlet weak var display: UILabel!
    var cubitoCHocolate: String!
    var cubitoCoco: String!
    var cubitoCacahuate: String!
    var cubitoFresa: String!
    var cubitoNaranja: String!
    var cubitoMango: String!
    var cuentaDeCubitos = String /*Expected member name or constructor call after type name*/


    override func viewDidLoad() {
        super.viewDidLoad()
  
        cuentaDeCubitos = cubitoCHocolate + cubitoCoco + cubitoCacahuate + cubitoFresa + cubitoNaranja + cubitoMango /*Expected member name or constructor call after type name*/

        display.text = "Tu pedido:" + "\n" + "Chocolate: "+cubitoCHocolate+"\n"+"Coco: "+cubitoCoco+"\n"+"Cacahuate: "+cubitoCacahuate+"\n"+"Fresa: "+cubitoFresa+"\n"+"Naranja: "+cubitoNaranja+"\n"+"Mango: "+cubitoMango
       if Int(cuentaDeCubitos) >= 1 { /*Cannot invoke initializer for type 'Int' with an argument list of type '(String.Type)'*/
            displaytotal.text = Int(cuentaDeCubitos) * 6 /*Cannot invoke initializer for type 'Int' with an argument list of type '(String.Type)'*/

        }
       else {
        displaytotal.text = "0"
        }
    }

can't convert string into integer to show in my label call 'displaytotal' i try many diferrents ways to fix it by readding the forum but i simple can't plz help

Your statement:

var cuentaDeCubitos = String

is not correct ; should be :

var cuentaDeCubitos : String = ""


You should not declare as implicitly unwrapped all the strings as

var cubitoCHocolate: String!


but simply

   var cubitoCHocolate: String

I do not see where the strings are initialized.


Int(cuentaDeCubitos) returns an optional, so you cannot compare to 1

You should write instead

let cuenta = Int(cuentaDeCubitos) ?? 0

If it is not a valid number string, then cuenta will be 0


this statement:

cuentaDeCubitos = cubitoCHocolate + cubitoCoco + cubitoCacahuate + cubitoFresa + cubitoNaranja + cubitoMango

will lead to a wrong computation


For istance if numlbers are "3", "2", "4", "1", "5", "6"

you will get

cuentaDeCubitos = "324156" which is not what you want


why do you multiply by 6 at the end ? In addition, text cannot be an Int, hence the error

displaytotal.text = Int(cuentaDeCubitos) * 6

Could write:

displaytotal.text =String(Int(cuentaDeCubitos) * 6)


So, I would change the whole like this:


import UIKit
class cuenta: UIViewController {

    @IBOutlet weak var displaytotal: UILabel!
    @IBOutlet weak var display: UILabel!
    var cubitoChocolate: String
    var cubitoCoco: String
    var cubitoCacahuate: String
    var cubitoFresa: String
    var cubitoNaranja: String
    var cubitoMango: String
    // NOT need var cuentaDeCubitos : String = ""
    var cuentaTotal = 0


    override func viewDidLoad() {
        super.viewDidLoad()

        let cuantaChocolate = Int(cubitoChocolate) ?? 0
        let cuantaCoco = Int(cubitoCoco) ?? 0
        let cuantaCacahuete = Int(cubitoCacahuate) ?? 0
        let cuantaFresa = Int(cubitoFresa) ?? 0
        let cuantaNaranja = Int(cubitoNaranja) ?? 0
        let cuantaMango = Int(cubitoMango) ?? 0
       // CHANGED  cuentaDeCubitos = cubitoChocolate + cubitoCoco + cubitoCacahuate + cubitoFresa + cubitoNaranja + cubitoMango /Expected member name or constructor call after type name*/
     cuentaTotal = cuantaChocolate + cuantaCoco + cuantaCacahuete + cuantaFresa + cuantaNaranja + cuantaMango

        display.text = "Tu pedido:" + "\n" + "Chocolate: "+cubitoChocolate+"\n"+"Coco: "+cubitoCoco+"\n"+"Cacahuate: "+cubitoCacahuate+"\n"+"Fresa: "+cubitoFresa+"\n"+"Naranja: "+cubitoNaranja+"\n"+"Mango: "+cubitoMango
       if cuentaTotal >= 1 {
            // displaytotal.text = Int(cuentaDeCubitos) * 6 /Cannot invoke initializer for type 'Int' with an argument list of type '(String.Type)'*/
            displaytotal.text = String(cuentaTotal * 6)     // Is this what you want to display ?
        }
       else {
        displaytotal.text = "0"
        }
    }

now a new error after overwriting to int, because i was trying to pull data from another viewcontroller by using a stepper



     import UIKit
   
    class items: UIViewController {
   
        var costocubito = 6.00
        var totalchocolate = 0
        var totalcoco = 0
    var totalcacahuate = 0
    var totalfresa = 0
    var totalnaranja = 0
    var totalmango = 0
   
   
    @IBAction func chocolatecounter(_ sender: UIStepper) {
        chocolate.text = String(sender.value) / the data is displayed here in the 'chocolate.text' outlet */
   
    }
   
   
    @IBAction func cococounter(_ sender: UIStepper) {
        coco.text = String(sender.value)
    }
   


    @IBAction func cacahuatecounter(_ sender: UIStepper) {
        cacahuate.text = String(sender.value)
    }
   


    @IBAction func fresacounter(_ sender: UIStepper) {
        fresa.text = String(sender.value)
    }
   
    @IBAction func naranjacounter(_ sender: UIStepper) {
        naranja.text = String(sender.value)
    }
   
    @IBAction func mangocounter(_ sender: UIStepper) {
        mango.text = String(sender.value)
    }
    @IBOutlet weak var chocolate: UILabel!
    @IBOutlet weak var coco: UILabel!
    @IBOutlet weak var cacahuate: UILabel!
    @IBOutlet weak var fresa: UILabel!
    @IBOutlet weak var naranja: UILabel!
    @IBOutlet weak var mango: UILabel!
   

   
   
  
   
   
   
   
    override func viewDidLoad() {
        super.viewDidLoad()


        // Do any additional setup after loading the view.
    }


        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }


    / prepare for segue func to store viewcontroller*/


        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            guard let cuentita = segue.destination as? cuenta  else { return  }
            cuentita.cubitoCHocolate = chocolate.text / Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoCoco = coco.text / Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoCacahuate = cacahuate.text/ Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoFresa = fresa.text/ Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoNaranja = naranja.text/ Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoMango = mango.text/ Cannot assign value of type 'String?' to type 'Int'*/
        }
    
        @IBAction func continuar(_ sender: Any) {
       
       
        }
       
        @IBAction func unwindToVC1(segue:UIStoryboardSegue) {
           
        }
        @IBAction func goBackToOneButtonTapped(_ sender: Any) {
            performSegue(withIdentifier: "unwindSegueToVC1", sender: self)
        }
        @IBAction func unwindToVC3(segue:UIStoryboardSegue) {}
import UIKit
class cuenta: UIViewController {
   
    @IBOutlet weak var displaytotal: UILabel!
    @IBOutlet weak var display: UILabel!
    var cubitoCHocolate: Int = Int()
    var cubitoCoco: Int = Int()
    var cubitoCacahuate: Int = Int()
    var cubitoFresa: Int = Int()
    var cubitoNaranja: Int = Int()
    var cubitoMango: Int = Int()
    var cuentaDeCubitos: Int = Int()
   
    override func viewDidLoad() {
        super.viewDidLoad()
       
        cuentaDeCubitos = cubitoCHocolate + cubitoCoco + cubitoCacahuate + cubitoFresa + cubitoNaranja + cubitoMango
       
        display.text = "Tu pedido:" + "\n" + "Chocolate: \(cubitoCHocolate)"+"\n"+"Coco: \(cubitoCoco)"+"\n"+"Cacahuate: \(cubitoCacahuate)"+"\n"+"Fresa: \(cubitoFresa)"+"\n"+"Naranja: \(cubitoNaranja)"+"\n"+"Mango: \(cubitoMango)"
       
       
        if cuentaDeCubitos >= 1 {
            displaytotal.text = "\(cuentaDeCubitos * 6)"
        }
        else {
            displaytotal.text = "0"
        }
    }

You have to change this, because types are wrong.

chocolate.text is an optional String (String?), and cuentita.cubitoCHocolate is an Int. So you have to get the Int from the String, first by unwrapping the text.

I assume here that text cannot be nil

To be totally safe, you could even write:

cuentita.cubitoCHocolate = Int(chocolate.text ?? "0") ?? 0


So the whole will be:

        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            guard let cuentita = segue.destination as? cuenta  else { return  }
            cuentita.cubitoCHocolate = Int(chocolate.text!) ?? 0 // That should correct: Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoCoco = Int(coco.text!) ?? 0 // Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoCacahuate = Int(cacahuate.text!) ?? 0 // Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoFresa = Int(fresa.text!) ?? 0 // Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoNaranja = Int(naranja.text!) ?? 0 // Cannot assign value of type 'String?' to type 'Int'*/
            cuentita.cubitoMango = Int(mango.text!) ?? 0 // Cannot assign value of type 'String?' to type 'Int'*/
        }

For clarity, instead of writing

var cubitoCHocolate: Int = Int()


I would write:

    var cubitoCHocolate: Int = 0
    var cubitoCoco: Int = 0
    var cubitoCacahuate: Int = 0
    var cubitoFresa: Int = 0
    var cubitoNaranja: Int = 0
    var cubitoMango: Int = 0
    var cuentaDeCubitos: Int = 0



Tell if all works now and don't forget to close the thread by marking the correct answer.

no errors detected but

the func segue is not working here is what it looks now


import UIKit
class items: UIViewController {

    @IBAction func chocolatecounter(_ sender: UIStepper) {
        chocolate.text = String(sender.value) /* i think this might be the problem because is a string and not INT */

    }


    @IBAction func cococounter(_ sender: UIStepper) {
        coco.text = String(sender.value) /* i think this might be the problem because is a string and not INT */
    }

    @IBAction func cacahuatecounter(_ sender: UIStepper) {
        cacahuate.text = String(sender.value) /* i think this might be the problem because is a string and not INT */
    }

    @IBAction func fresacounter(_ sender: UIStepper) {
        fresa.text = String(sender.value) /* i think this might be the problem because is a string and not INT */
    }

    @IBAction func naranjacounter(_ sender: UIStepper) {
        naranja.text = String(sender.value) /* i think this might be the problem because is a string and not INT */
    }

    @IBAction func mangocounter(_ sender: UIStepper) {
        mango.text = String(sender.value) /* i think this might be the problem because is a string and not INT */
    }
    @IBOutlet weak var chocolate: UILabel!
    @IBOutlet weak var coco: UILabel!
    @IBOutlet weak var cacahuate: UILabel!
    @IBOutlet weak var fresa: UILabel!
    @IBOutlet weak var naranja: UILabel!
    @IBOutlet weak var mango: UILabel!









    override func viewDidLoad() {
        super.viewDidLoad()
        /
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        /
    }
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        guard let cuentita = segue.destination as? cuenta  else { return  }
        cuentita.cubitoCHocolate = Int(chocolate.text!) ?? 0
        cuentita.cubitoCoco = Int(coco.text!) ?? 0
        cuentita.cubitoCacahuate = Int(cacahuate.text!) ?? 0
        cuentita.cubitoFresa = Int(fresa.text!) ?? 0
        cuentita.cubitoNaranja = Int(naranja.text!) ?? 0
        cuentita.cubitoMango = Int(mango.text!) ?? 0
    }

    @IBAction func continuar(_ sender: Any) {


    }

    @IBAction func unwindToVC1(segue:UIStoryboardSegue) {

    }
    @IBAction func goBackToOneButtonTapped(_ sender: Any) {
        performSegue(withIdentifier: "unwindSegueToVC1", sender: self)
    }
    @IBAction func unwindToVC3(segue:UIStoryboardSegue) {}
    /
    /
    /
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        /
        /
    }
    */
}
import UIKit
class cuenta: UIViewController {
   
    @IBOutlet weak var displaytotal: UILabel!
    @IBOutlet weak var display: UILabel!
    var cubitoCHocolate: Int = 0
    var cubitoCoco: Int = 0
    var cubitoCacahuate: Int = 0
    var cubitoFresa: Int = 0
    var cubitoNaranja: Int = 0
    var cubitoMango: Int = 0
    var cuentaDeCubitos: Int = 0
   
    override func viewDidLoad() {
        super.viewDidLoad()
       
        cuentaDeCubitos = cubitoCHocolate + cubitoCoco + cubitoCacahuate + cubitoFresa + cubitoNaranja + cubitoMango
       
        display.text = "Tu pedido:" + "\n" + "Chocolate: \(cubitoCHocolate)"+"\n"+"Coco: \(cubitoCoco)"+"\n"+"Cacahuate: \(cubitoCacahuate)"+"\n"+"Fresa: \(cubitoFresa)"+"\n"+"Naranja: \(cubitoNaranja)"+"\n"+"Mango: \(cubitoMango)"
       
       
        if cuentaDeCubitos >= 1 {
            displaytotal.text = "Tu total a pagar es: " + "\(cuentaDeCubitos * 6)"
        }
        else {
            displaytotal.text = "0"
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        /
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
    }
   
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
    @IBAction func unwindToVC3(segue:UIStoryboardSegue) {}
    @IBAction func goBackToOneButtonTapped(_ sender: Any) {
        performSegue(withIdentifier: "unwindSegueToVC3", sender: self)
    }
    @IBAction func unwindToVC4(segue:UIStoryboardSegue) {}

I don't understand why you define unwindToVC3 in both classes.


It should be only defined in items class, not in cuenta.

In cuenta view (in IB), you just connect the button used to return to the exit icon at the very top right of the view.


Can you describe precisely what doesn'y work and if you get an error message.


Note: names for classes should start with uppercase :

class Cuenta: UIViewController
class Items: UIViewController

i had 4 viewcontrollers connected with unwindToVC that's why unwindToVC3 is in both classes

MR Claude thanks so much for all your help through this app of mine

i had post in several pages for answers and nobody help me like you in stack overflow i even got 10 dislikes for not filling with "extra information"


i would like to do just 1 more thing for me, would you please give me an example of passing data between viewcontrollers with INT data?

i think i don't have a clear idea of passing data and that's why i'm keeping getting errors


i'm using a stepper to get the value from the user and giving 'chocolate' the value

@IBAction funcchocolatecounter(_ sender: UIStepper) {
        chocolate.text = String(sender.value)


and then sending that data to cuentaViewcontroller

var cubitoCHocolate: Int! = 0
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        guard let cuentita = segue.destination as? cuenta  else { return  }
        cuentita.cubitoCHocolate = Int(chocolate.text!) ?? 0


and then display it on a label in cuentaViewcontroller


var cubitoCHocolate: Int! = 0

override func viewDidLoad() {
        super.viewDidLoad()
      
        cuentaDeCubitos = cubitoCHocolate + cubitoCoco + cubitoCacahuate + cubitoFresa + cubitoNaranja + cubitoMango
      
        display.text = "Tu pedido:" + "\n" + "Chocolate: \(cubitoCHocolate)"+"\n"+"Coco: \(cubitoCoco)"+"\n"+"Cacahuate: \(cubitoCacahuate)"+"\n"+"Fresa: \(cubitoFresa)"+"\n"+"Naranja: \(cubitoNaranja)"+"\n"+"Mango: \(cubitoMango)"
      
      
        if cuentaDeCubitos >= 1 {
            displaytotal.text = "Tu total a pagar es: " + "\(cuentaDeCubitos * 6)"
        }
        else {
            displaytotal.text = "0"
        }
    }


if you use a stepper as i do to the example would be perfect haha, thanks

If I understand well, you want to pass the value and not only the text ? Right ?

What errors do you get exactly ?


Passing data through segue is very simple in fact.


You declare a property (var) in the destination controller ; of course, this property must not be private.

Then, in the prepare for segue, in the originating controller, you set the var to the value you want.

That is very important if this value is to be shown in an outlet in the destination controller : you cannot set directly (from the originating controller) the outlet, because it may not yet be loaded. So, you pass the value and use this value in the viewDidload of the destination controller to set the outlet content.


In Items class, you should have :


@IBAction func chocolatecounter(_ sender: UIStepper) {      // missing a space after func
        chocolate.text = String(sender.value)


No need to declare here

var cubitoCHocolate: Int! = 0


And change in prepare as well :

Question: what is the name of the class ? cuenta or Cuenta (which is better)

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        guard let cuentita = segue.destination as? cuenta  else { return  }     // Check cuenta or Cuenta
        cuentita.cubitoCHocolate = Int(chocolate.text) ?? 0


In Cuenta class:

cubitoCHocolate should not be declared as optional (unwrapped) but simply Int


var cubitoCHocolate: Int = 0

override func viewDidLoad() {
        super.viewDidLoad()

        cuentaDeCubitos = cubitoCHocolate + cubitoCoco + cubitoCacahuate + cubitoFresa + cubitoNaranja + cubitoMango

        display.text = "Tu pedido:" + "\n" + "Chocolate: \(cubitoCHocolate)"+"\n"+"Coco: \(cubitoCoco)"+"\n"+"Cacahuate: \(cubitoCacahuate)"+"\n"+"Fresa: \(cubitoFresa)"+"\n"+"Naranja: \(cubitoNaranja)"+"\n"+"Mango: \(cubitoMango)"

        if cuentaDeCubitos >= 1 {
            displaytotal.text = "Tu total a pagar es: \(cuentaDeCubitos * 6)"     // some quotes were useless
        }
        else {
            displaytotal.text = "0"
        }
    }

cuenta is the name of the class(original viewcontroller)

and now i'm getting this error in items class


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        guard let cuentita = segue.destination as? cuenta  else { return  }
        cuentita.cubitoCHocolate = Int(chocolate.text) ?? 0 //Value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
        cuentita.cubitoCoco = Int(coco.text) ?? 0   //Value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
        cuentita.cubitoCacahuate = Int(cacahuate.text) ?? 0 //Value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
        cuentita.cubitoFresa = Int(fresa.text) ?? 0. //Value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
        cuentita.cubitoNaranja = Int(naranja.text) ?? 0. //Value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
        cuentita.cubitoMango = Int(mango.text) ?? 0. //Value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
    }


items class all code


import UIKit
class items: UIViewController {
  
    @IBAction func chocolatecounter(_ sender: UIStepper) {
        chocolate.text = String(sender.value)
    }
    @IBAction func cococounter(_ sender: UIStepper) {
        coco.text = String(sender.value)
    }
    @IBAction func cacahuatecounter(_ sender: UIStepper) {
        cacahuate.text = String(sender.value)
    }
    @IBAction func fresacounter(_ sender: UIStepper) {
        fresa.text = String(sender.value)
    }
    @IBAction func naranjacounter(_ sender: UIStepper) {
        naranja.text = String(sender.value)
    }
    @IBAction func mangocounter(_ sender: UIStepper) {
        mango.text = String(sender.value)
    }
    @IBOutlet weak var chocolate: UILabel!
    @IBOutlet weak var coco: UILabel!
    @IBOutlet weak var cacahuate: UILabel!
    @IBOutlet weak var fresa: UILabel!
    @IBOutlet weak var naranja: UILabel!
    @IBOutlet weak var mango: UILabel!
  
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        guard let cuentita = segue.destination as? cuenta  else { return  }
        cuentita.cubitoCHocolate = Int(chocolate.text) ?? 0
        cuentita.cubitoCoco = Int(coco.text) ?? 0
        cuentita.cubitoCacahuate = Int(cacahuate.text) ?? 0
        cuentita.cubitoFresa = Int(fresa.text) ?? 0
        cuentita.cubitoNaranja = Int(naranja.text) ?? 0
        cuentita.cubitoMango = Int(mango.text) ?? 0
    }

    @IBAction func continuar(_ sender: Any) {
  
  
    }
  
    @IBAction func unwindToVC1(segue:UIStoryboardSegue) {
      
    }
    @IBAction func goBackToOneButtonTapped(_ sender: Any) {
        performSegue(withIdentifier: "unwindSegueToVC1", sender: self)
    }
    @IBAction func unwindToVC3(segue:UIStoryboardSegue) {}



cuenta class all code


import UIKit
class cuenta: UIViewController {
   
    @IBAction func captura(_ sender: Any) {
        if numeroCel.text == ""
        {
        displaytotal.text = "No introdujiste tu número celular"  + "\n" + "Tu total a pagar es: "
        }
        else
        {
            displaytotal.text = "Tu número es: " + numeroCel.text! + "\n" + "Tu total a pagar es: "
        }
    }
  
   
    @IBOutlet weak var numeroCel: UITextField!
    @IBOutlet weak var displaytotal: UILabel!
    @IBOutlet weak var display: UILabel!
    var cubitoCHocolate: Int = 0
    var cubitoCoco: Int = 0
    var cubitoCacahuate: Int = 0
    var cubitoFresa: Int = 0
    var cubitoNaranja: Int = 0
    var cubitoMango: Int = 0
    var cuentaDeCubitos: Int = 0
  
    override func viewDidLoad() {
        super.viewDidLoad()
       
        cuentaDeCubitos = cubitoCHocolate + cubitoCoco + cubitoCacahuate + cubitoFresa + cubitoNaranja + cubitoMango
       
        display.text = "Tu pedido:" + "\n" + "Chocolate: \(cubitoCHocolate)"+"\n"+"Coco: \(cubitoCoco)"+"\n"+"Cacahuate: \(cubitoCacahuate)"+"\n"+"Fresa: \(cubitoFresa)"+"\n"+"Naranja: \(cubitoNaranja)"+"\n"+"Mango: \(cubitoMango)"
       
        if cuentaDeCubitos >= 1 {
            displaytotal.text = "Tu total a pagar es: \(cuentaDeCubitos * 6)"
        }
        else {
            displaytotal.text = "0"
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        /
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
    }
   
   
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
    @IBAction func unwindToVC3(segue:UIStoryboardSegue) {}
    @IBAction func goBackToOneButtonTapped(_ sender: Any) {
        performSegue(withIdentifier: "unwindSegueToVC3", sender: self)
    }
    @IBAction func unwindToVC4(segue:UIStoryboardSegue) {}
  
}

i try to unwrap

cuentita.cubitoCHocolate = Int(chocolate.text!) ?? 0


but it crash the app

and this error appears in the console


2018-05-09 14:48:22.123528-0500 venta[4355:2000820] -[venta.items continuar:]: unrecognized selector sent to instance 0x155d428f0

2018-05-09 14:48:22.127562-0500 venta[4355:2000820] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[venta.items continuar:]: unrecognized selector sent to instance 0x155d428f0'

*** First throw call stack:

(0x184296d8c 0x1834505ec 0x1842a4098 0x18e34ade4 0x18429c5c8 0x18418241c 0x18dfc66c8 0x18e0e78a4 0x18dfcc77c 0x18e1021dc 0x18e5a7dd8 0x18e5a4b50 0x18423e910 0x18423c238 0x18423c884 0x18415cda8 0x18613f020 0x18e13d78c 0x1045fd02c 0x183bedfc0)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb)

Error is normal. My mistake

chocolate.text is an optional, so you need to write

        cuentita.cubitoCHocolate = Int(chocolate.text!) ?? 0
        cuentita.cubitoCoco = Int(coco.text!) ?? 0
        cuentita.cubitoCacahuate = Int(cacahuate.text!) ?? 0
        cuentita.cubitoFresa = Int(fresa.text!) ?? 0
        cuentita.cubitoNaranja = Int(naranja.text!) ?? 0
        cuentita.cubitoMango = Int(mango.text!) ?? 0

To be totally safe, you could even write, as I told you on a post on may 7:

cuentita.cubitoCHocolate = Int(chocolate.text ?? "0") ?? 0


So the whole will be

        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            guard let cuentita = segue.destination as? cuenta  else { return  }
            cuentita.cubitoCHocolate = Int(chocolate.text ?? "0") ?? 0
            cuentita.cubitoCoco = Int(coco.tex ?? "0") ?? 0
            cuentita.cubitoCacahuate = Int(cacahuate.text ?? "0") ?? 0
            cuentita.cubitoFresa = Int(fresa.text ?? "0") ?? 0
            cuentita.cubitoNaranja = Int(naranja.text ?? "0") ?? 0
            cuentita.cubitoMango = Int(mango.text ?? "0") ?? 0
        }

app crash


2018-05-09 16:48:45.312165-0500 venta[4494:2052388] -[venta.items continuar:]: unrecognized selector sent to instance 0x10283f2b0

2018-05-09 16:48:45.313808-0500 venta[4494:2052388] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[venta.items continuar:]: unrecognized selector sent to instance 0x10283f2b0'

*** First throw call stack:

(0x184296d8c 0x1834505ec 0x1842a4098 0x18e34ade4 0x18429c5c8 0x18418241c 0x18dfc66c8 0x18e0e78a4 0x18dfcc77c 0x18e1021dc 0x18e049a48 0x18e03e8f8 0x18e03d238 0x18e81ec0c 0x18e8211b8 0x18e81a258 0x18423f404 0x18423ec2c 0x18423c79c 0x18415cda8 0x18613f020 0x18e13d78c 0x1007d0ee0 0x183bedfc0)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb)

can't convert string into int to display on label
 
 
Q