Swift 闭包表达式为3
闭包表达式未使用错误 有人能解决问题吗?我怎样才能正确地解决问题?我怎样才能在代码中毫无问题地使用Swift 闭包表达式为3,swift,if-statement,Swift,If Statement,闭包表达式未使用错误 有人能解决问题吗?我怎样才能正确地解决问题?我怎样才能在代码中毫无问题地使用if-else语句 func storeToCoreData(product_Name : String,product_Brand : String,original_Price : String,discount_Price : String,userPhotoString : String,catagory : String, urlCoreData : String){ if ca
if-else
语句
func storeToCoreData(product_Name : String,product_Brand : String,original_Price : String,discount_Price : String,userPhotoString : String,catagory : String, urlCoreData : String){
if catagory == "Tools" {
switch (urlCoreData){
case "Mens_shirt":
coreVariables.mens_Shirt.StoreProduct(product_Name: product_Name, product_Brand: product_Brand, product_Price: original_Price, product_Discount: discount_Price, product_Image: userPhotoString)
break
case "Mens_sweatshirt" :
coreVariables.mens_SweatShirt.StoreProduct(product_Name: product_Name, product_Brand: product_Brand, product_Price: original_Price, product_Discount: discount_Price, product_Image: userPhotoString)
break
case "Mens_tshirt":
coreVariables.mens_Tshirt.StoreProduct(product_Name: product_Name, product_Brand: product_Brand, product_Price: original_Price, product_Discount: discount_Price, product_Image: userPhotoString)
break
default:
break
}
} else {
switch (urlCoreData){
case "Women_kurta" :
coreVariables.womens_Kurta.StoreProduct(product_Name: product_Name, product_Brand: product_Brand, product_Price: original_Price, product_Discount: discount_Price, product_Image: userPhotoString)
break
case "Women_saree" :
coreVariables.womens_Saree.StoreProduct(product_Name: product_Name, product_Brand: product_Brand, product_Price: original_Price, product_Discount: discount_Price, product_Image: userPhotoString)
break
case "Women_tops":
coreVariables.womens_Tops.StoreProduct(product_Name: product_Name, product_Brand: product_Brand, product_Price: original_Price, product_Discount: discount_Price, product_Image: userPhotoString)
break
default:
break
}
} else {
switch (urlCoreData){
case "first" :
coreVariables.first.StoreProduct(product_Name: product_Name, product_Brand: product_Brand, product_Price: original_Price, product_Discount: discount_Price, product_Image: userPhotoString)
break
case "second" :
coreVariables.second.StoreProduct(product_Name: product_Name, product_Brand: product_Brand, product_Price: original_Price, product_Discount: discount_Price, product_Image: userPhotoString)
break
case "third":
coreVariables.third.StoreProduct(product_Name: product_Name, product_Brand: product_Brand, product_Price: original_Price, product_Discount: discount_Price, product_Image: userPhotoString)
break
default:
break
}
}
首先,这是斯威夫特:
情况下无中断语句(除了开关
)默认值
参数周围没有括号开关
- 没有蛇壳变量名李>
出现此错误的原因是第一个
else
子句捕获了分类!=“工具”
因此第二个else
将永远无法到达
例如,如果需要第二个else
条件,则必须插入第二个If
条件
if catagory == "Tools" {
...
} else if catagory == "Something Else" {
...
} else {
...
}