如何在没有if条件swift的情况下验证多个值[关闭]
Posted
技术标签:
【中文标题】如何在没有if条件swift的情况下验证多个值[关闭]【英文标题】:How to validate multiple values without if condition swift [closed] 【发布时间】:2021-06-01 18:44:37 【问题描述】:这是在条件语句中的一种可能方式
if let offer = self.offer_visitor_["Offer"], let video = self.offer_visitor_["VideoReward"], let bday = self.offer_visitor_["BirthdayReward"],let Promotional = self.offer_visitor_["promotional"]
if !offer.isEmpty && !video.isEmpty && !bday.isEmpty && !Promotional.isEmpty
return 4
else if !offer.isEmpty && !bday.isEmpty && !video.isEmpty
return 3
else if !offer.isEmpty && !video.isEmpty && !Promotional.isEmpty
return 3
else if !offer.isEmpty && !bday.isEmpty && !Promotional.isEmpty
return 3
else if !video.isEmpty && !bday.isEmpty && !Promotional.isEmpty
return 3
else if !offer.isEmpty && !video.isEmpty
return 2
else if !offer.isEmpty && !bday.isEmpty
return 2
else if !offer.isEmpty && !Promotional.isEmpty
return 2
else if !video.isEmpty && !bday.isEmpty
return 2
else if !video.isEmpty && !Promotional.isEmpty
return 2
else if !bday.isEmpty && !Promotional.isEmpty
return 2
else if !offer.isEmpty
return 1
else if !video.isEmpty
return 1
else if !bday.isEmpty
return 1
else if !Promotional.isEmpty
return 1
else
UIView.transition(with: self.noHistory_Label!,
duration: 0.35,
options: .transitionCrossDissolve,
animations: [weak self] in
self?.noHistory_Label?.text = UserDefaults.language == "ar" ? ArabicLanguageFile.NoOffers : EnglishLanguageFile.NoOffers
, completion: nil)
return 0
else
UIView.transition(with: self.noHistory_Label!,
duration: 1,
options: .transitionCrossDissolve,
animations: [weak self] in
self?.noHistory_Label?.text = UserDefaults.language == "ar" ? ArabicLanguageFile.NoOffers : EnglishLanguageFile.NoOffers
, completion: nil)
return 0
如果动态值是这种使用方式 类似的东西
let count = [arrayData1["Available Offers"]?.count != 0, arrayData1["Redeemtion Offers"]?.count != 0, arrayData1["Redeemtion Vouchers"]?.count != 0, self .arrayData1["Available Vouchers"]?.count != 0].filter $0 == true .count
地图 过滤
谢谢
【问题讨论】:
返回的这些神奇数字是什么? 你要数什么? 【参考方案1】:据我了解,这只是一种非常复杂的方法来计算这 4 件事中有多少不是空的。看起来很简单:
let emptyObjectCount = [offer, video, bday, promotional]
.filter !$0.isEmpty
.count
虽然这些变量名没有意义,但你应该改进它们。
【讨论】:
也许算不!空集合??♂️以上是关于如何在没有if条件swift的情况下验证多个值[关闭]的主要内容,如果未能解决你的问题,请参考以下文章
robot framework ——关键字run keyword if 如何在一个条件下接多个执行语句,以及如何写复杂条件句