复合主键领域/ swift

编程入门 行业动态 更新时间:2024-10-28 18:27:06
本文介绍了复合主键领域/ swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是快速和领域的新手。我想制作复合主键,当我尝试这样的事情时:

I'm new to swift and realm. I want to make a composite primary key and when I'm trying something like this :

class DbLocation : Object { dynamic var id = 0 dynamic var tourId = 0 dynamic var uuid : String { return "\(id)\(tourId)" } override static func primaryKey() -> String? { return "uuid" } }

我'我收到此错误:'对象'DbLocation'上不存在主键属性'uuid'

I'm getting this error : 'Primary key property 'uuid' does not exist on object 'DbLocation'

任何人都可以帮我解决如何创建的示例复合主键?

Anyone can help me out with an example how to create a composite primary key ?

推荐答案

这应该给你答案:

class DbLocation: Object { dynamic var id = 0 dynamic var tourId = 0 func setCompoundID(id: Int) { self.id = id compoundKey = compoundKeyValue() } func setCompoundTourId(tourId: Int) { self.tourId = tourId compoundKey = compoundKeyValue() } dynamic lazy var compoundKey: String = selfpoundKeyValue() override static func primaryKey() -> String? { return "compoundKey" } func compoundKeyValue() -> String { return "\(id)\(tourId)" } }

自定义设置器确保复合键始终更新,懒惰关键字确保第一次访问它时,它将从您已设置的内容中派生出来。

The custom setters make sure, that the compoundKey is always updated, the lazy key word makes sure that the first time you access it, it will be derived from what you've already set.

在此主题中了解有关此主题的更多信息这个问题一直存在争议。

Find out more on this topic in this thread where this issue has been debated.

更多推荐

复合主键领域/ swift

本文发布于:2023-10-22 23:27:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519043.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主键   领域   swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!