我是编程和尝试使用UISwitches应用过滤器的新手
目前,我有:
尝试的事情:
目标:将多个过滤器应用于领域数据库结果
用户界面:
领域数据库:
class Question: Object {
@objc dynamic var neverAttempted: Bool = true
@objc dynamic var correct: Int = 0
@objc dynamic var flagged: Bool = false
@objc dynamic var subject: String = ""
}
correct = 1;
neverAttempted = true;
flagged = false;
subject = Law;
视图控制器:
import UIKit
import RealmSwift
class OptionsViewController: UIViewController {
@IBOutlet weak var totalQuestionsLabel: UILabel!
@IBOutlet weak var totalQuestionSlider: UISlider!
var neverAttempted = ""
var correct = ""
var flagged = false
var subject = ""
let realmOne = try! Realm()
var questionBank: Results<Question>! {
get {
return realmOne.objects(Question.self)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
func updateQuestionBank() {
let updatedQuestionBank = realmOne.objects(Question.self)
.filter(//Apply filter//)
totalQuestionsLabel.text = String(updatedQuestionBank.count)
print (updatedQuestionBank)
}
@IBAction func subjectSwitch(_ sender: UISwitch) {
if sender.isOn == true {
subject =
updateQuestionBank()
}
}
@IBAction func flaggedSwitch(_ sender: UISwitch) {
if sender.isOn == true {
flagged =
updateQuestionBank()
}
}
@IBAction func neverAttemptedSwitch(_ sender: UISwitch) {
if sender.isOn == true {
neverAttempted =
}
}
@IBAction func correctOnlyOnceSwitch(_ sender: UISwitch) {
if sender.isOn == true {
correct =
updateQuestionBank()
}
}