Отдельные данные Realm Bool в 2 разделах - PullRequest
0 голосов
/ 29 июня 2018

Добрый день! У меня небольшая проблема. Я хочу отделить данные от Realm DB по значению Bool (true и false). Если данные Bool currencyStatusCode == true, тогда укажите currencyName, currencyCode и сальдо в первом разделе таблицы «Активные счета», если данные Bool currencyStatusCode == false, то во второй раздел «Неактивные счета». Как и я добавляю образ БД смотри. Буду очень признателен за вашу помощь.

var sections = ["Active accounts", "Inactive accounts"]

@IBOutlet weak var accountManagerTableView: UITableView!


let realm = try? Realm()
let accounts = try! Realm().objects(currencyAccounts.self).sorted(byKeyPath: "currencyID")
var accountManager: currencyAccounts?
var accountsRecord: Results<currencyAccounts> {
    get {
        return realm!.objects(currencyAccounts.self)
    }
}
override func numberOfSections(in tableView: UITableView) -> Int {
    return sections.count
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return sections[section]
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return accounts.count

 /*   switch (section) {
    case 0:


            return accounts.count
     break;


    case 1:



            return accounts.count
            break;

    default:
        break;

    }

return section
   */


    }

   override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


    let cell = accountManagerTableView.dequeueReusableCell(withIdentifier: "activeCurrencyCell", for: indexPath) as! accountManagerTableViewCell

    let sortingtInTableView = realm?.objects(currencyAccounts.self).sorted(byKeyPath: "currencyID", ascending: true)
    let currentUserBalances = sortingtInTableView![indexPath.row]


            cell.currencyFullName.text = currentUserBalances.currencyName
            cell.currencyTitle.text = currentUserBalances.currencyCode
            cell.selectedAccountBalance.text = String(currentUserBalances.currencyBalance)


    return cell

}

Данные БД Царства

1 Ответ

0 голосов
/ 29 июня 2018

Вы снова используете фильтр Realm самого объекта. Пожалуйста, обратитесь к документации для более подробной информации. Пожалуйста, найдите код для фильтрации активных и неактивных учетных записей:

let realm = try! Realm()

let activeAccounts = realm.objects(Dog.self).filter("currencyStatusCode = true").sorted(byKeyPath: "currencyID")


// Persist your data easily
try! realm.write {
    realm.add(activeAccounts)
}


let realm = try! Realm()

let inactiveAccounts = realm.objects(Dog.self).filter("currencyStatusCode = false").sorted(byKeyPath: "currencyID")


// Persist your data easily
try! realm.write {
    realm.add(inactiveAccounts)
}
...