【问题标题】:Cannot access realm fetched data无法访问领域获取的数据
【发布时间】:2017-03-12 20:21:33
【问题描述】:

我通过

成功获取了我的Board数据
let boards: [Board] = try! db.fetch(FetchRequest<Board>())

之后我会遍历 boards 并制作一个

print(board)

最多输出:

Board {
    id = 1;
    name = The Name;
    shortDescription = The Description;
    slug = the_name;
}

但是当我想直接访问 board 名称时,例如

 board.name

抛出以下错误:

fatal error: unexpectedly found nil while unwrapping an Optional value

我的错误是什么? 如果 board 不是一个对象,我怎样才能实现它是一个对象?

我正在使用:

SugarRecord
ObjectMapper 
RealmSwift
ObjectMapper_Realm

【问题讨论】:

    标签: ios swift realm objectmapper


    【解决方案1】:

    通过 ObjectMapper_Realm 中缺少的文档,我没有

     dynamic
    

    我的 var 声明前面的关键字。

    【讨论】:

    • 但您也在创建一个数组 [Board],但将其视为 board.name 中的一个实例,这对您有何帮助
    • 我在板上迭代。第一个版本有错字,将“board”切换为“boards”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多