领域对象缺少除primaryKey之外的所有属性 [英] Realm object is missing all properties except primaryKey

查看:80
本文介绍了领域对象缺少除primaryKey之外的所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我的tableViewDataSource依赖的RealmObject模型. cellForRowAtIndexPath1方法可以很好地访问属性,但是didSelectRowAtIndexPath从Realm对象获取所有空属性.我猜测这与传递持久化的Realm对象有关,但是我不确定在哪里修复它.

I have a RealmObject model that my tableViewDataSource depends on. The cellForRowAtIndexPath1 method is able to access the properties fine, but the didSelectRowAtIndexPath gets all empty properties from the Realm object. I'm guessing this has to do with passing persisted Realm objects around but I'm not sure where to fix it.

//viewController...
override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    let realm = try! Realm()
    let books = realm.objects(Book)
    viewModel = BookListViewModel(books: Array(books), onSelection: onSelection, onDeleteFailure: onDeleteFailure)
}
//end viewController

extension BookListViewModel: UITableViewDataSource {
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(BookTableViewCell.nibName, forIndexPath: indexPath) as! BookTableViewCell
        cell.bind(bookCellViewModels[indexPath.row])

        // NOTE:
        // bookCellViewModels[indexPath.row].book all properties are valid strings
        return cell
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return bookCellViewModels.count
    }
}

extension BookListViewModel: UITableViewDelegate {
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let book = bookCellViewModels[indexPath.row].book

        // NOTE:
        // all book properties are empty string or nil
        onSelection(book)
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
    }
}

推荐答案

您的调试器可能会向您显示Realm对象的所有空属性值,因为您缺少了

Your debugger is likely showing you all empty property values for the Realm object, because you're missing the LLDB plugin.

LLDB插件与 Realm Xcode插件捆绑在一起.可在恶魔岛上使用.

The LLDB plugin comes bundled with the Realm Xcode plugin, which is available on Alcatraz.

  1. 安装Alcatraz(如果尚未安装).

  1. Install Alcatraz, if not already installed.

curl -fsSL https://raw.githubusercontent.com/supermarin/Alcatraz/deploy/Scripts/install.sh | sh

  • 在Xcode中打开程序包管理器(⇧⌘9或Windows>程序包管理器)

  • Open the Package Manager in Xcode (⇧⌘9 or Windows > Package Manager)

    搜索 RealmPlugin

    1. 退出并重新启动Xcode以确保插件已加载

    编译自己

    您还可以通过打开

    Compile yourself

    You can also install the plugin manually by opening plugin/RealmPlugin.xcodeproj contained in the release zip and clicking build.

    或者,您可以按照链接脚本的第一个代码注释中的建议进行安装,也可以仅执行以下脚本:

    Alternatively, you can install it as advised in the first code comments of the linked scripts or just execute the script below:

    mkdir -p ~/Library/Application\ Support/Realm
    wget -O ~/Library/Application\ Support/Realm/rlm_lldb.py https://raw.githubusercontent.com/realm/realm-cocoa/master/plugin/rlm_lldb.py
    touch ~/.lldbinit
    grep -q "rlm_lldb.py" ~/.lldbinit || echo "command script import "~/Library/Application Support/Realm/rlm_lldb.py" --allow-reload" >> .lldbinit
    

    这篇关于领域对象缺少除primaryKey之外的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆