如何将多个过滤器应用于领域数据库结果

时间:2020-06-07 15:21:58

标签: ios swift subquery nspredicate realm-database

我是编程和尝试使用UISwitches应用过滤器的新手

目前,我有:

  1. 返回所有对象的领域数据库
  2. 使用开关发送过滤器的UI

尝试的事情:

  1. 子查询,但是我不知道将其写入领域的正确格式

目标:将多个过滤器应用于领域数据库结果

用户界面:

enter image description here

领域数据库:

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()
    }

}

0 个答案:

没有答案