【发布时间】: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
地图 过滤
谢谢
【问题讨论】:
-
返回的这些神奇数字是什么?
-
你要数什么?
标签: ios arrays swift if-statement