如何将表达式分解为不同的子表达式?
How to break up expression into distinct sub-expressions?
我在 Swift 中遇到了这个错误
“编译器无法在合理的时间内对该表达式进行类型检查;尝试将表达式分解为不同的子表达式”
这是抛出错误的代码。
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)
}
特别是这部分代码错误指向:
StaticData.singleton.cardAddress = obj.street+" ,"+obj.city+" "+obj.country
只需将 +
运算符替换为字符串连接即可。通常,使用字符串连接是优于使用 +
运算符的首选方法。
StaticData.singleton.cardAddress = "\(obj.street) ,\(obj.city) \(obj.country)"
我在 Swift 中遇到了这个错误 “编译器无法在合理的时间内对该表达式进行类型检查;尝试将表达式分解为不同的子表达式”
这是抛出错误的代码。
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)
}
特别是这部分代码错误指向:
StaticData.singleton.cardAddress = obj.street+" ,"+obj.city+" "+obj.country
只需将 +
运算符替换为字符串连接即可。通常,使用字符串连接是优于使用 +
运算符的首选方法。
StaticData.singleton.cardAddress = "\(obj.street) ,\(obj.city) \(obj.country)"