0

I got this error in Swift "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions"

Here is the code that is throwing the error.

             let obj = self.AddressList[indexPath.row] as! Address
//            let a:String! = obj.street+" ,"+obj.city+" "+obj.country
//            let b:String! = obj.country
            StaticData.singleton.cardAddress = obj.street+" ,"+obj.city+" "+obj.country
            StaticData.singleton.AddressID = obj.id
            StaticData.singleton.cart_addresstotal = obj.total_amount
            StaticData.singleton.cart_addressFee = obj.delivery_fee
            DispatchQueue.main.async {
                self.dismiss(animated:true, completion:nil)
            }

in particular it is this portion of the code in which the error is pointing towards:

    StaticData.singleton.cardAddress = obj.street+" ,"+obj.city+" "+obj.country
Aaron34
  • 7
  • 4

1 Answers1

0

Just replace the + operator with String concatenation. In general, using String concatenation is the preferred approach over using the + operator.

StaticData.singleton.cardAddress = "\(obj.street) ,\(obj.city) \(obj.country)"
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
  • you are a life saver thank you so much! worked great! ...not sure why I didn't just think of that – Aaron34 Nov 17 '20 at 02:09
  • @Aaron34 Glad I could help. If you found my answer useful, please consider accepting it. If you're unsure how to do that, you can read [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers). – Dávid Pásztor Nov 17 '20 at 09:31