Primary key in Realm

Issue #4 Realm is great. But without primary key, it will duplicate the record, like https://github.com/realm/realm-java/issues/2730, http://stackoverflow.com/questions/32322460/should-i-define-the-primary-key-for-each-entity-in-realm, โ€ฆ So to force ourselves into the good habit of declaring primary key, we can leverage Swift protocol Create primary constrain protocol like this protocol PrimaryKeyAware { var id: Int { get } static func primaryKey() -> String? } and conform it in out Realm object class Profile: Object, PrimaryKeyAware { dynamic var firstName: String = "" dynamic var lastName: String = "" dynamic var id: Int = 0 override static func primaryKey() -> String?...

April 26, 2017 ยท 1 min ยท Khoa Pham