在swift上使用realm 1.0.1的复合主键

时间:2016-06-21 06:44:04

标签: swift swift2 realm

Lastest Realm Swift 1.0.1 我跟着这个 composite primary key realm/swift

enter image description here

显示错误

enter image description here

如何使用Swift编写?

1 个答案:

答案 0 :(得分:0)

您需要从变量声明中删除lazy说明符,作为错误消息声明不支持此类属性的方式。您不希望忽略该属性,因为您希望将其用作主键。

除此之外,我建议将复合键中的整数组件分开。 (例如"\(id)|\(tourId)")否则,您最终可能会使用相同的冲突主键使用不同的对象。例如对于compoundKey="123"组合,您可以使用id=1 tourId=23的对象,也可以为id=12 tourId=3提供对象。

相关问题