Relational database in Realm?

自古美人都是妖i 提交于 2019-12-04 19:06:39

You can use RLMArray , where RLMArray is the container type in Realm used to define to-many relationships. As mentioned in the official Realm documentation for objective c check example here. Also go through this link it might help RLMArray doc

RLMArray is used for the relational database concept in realm. You can try like this:

#import <Realm/Realm.h>

@class User;

// User model
@interface User : RLMObject
@property NSString *name;
@property NSString *user_id;
@property RLMArray<Watchlist *><Watchlist> *watchlist;
@end
RLM_ARRAY_TYPE(Dog) // define RLMArray<Dog>

// Watchlist model
@interface Watchlist : RLMObject
@property NSString *id;
@property NSInteger *activity;
@property NSInteger *cost;

@end
RLM_ARRAY_TYPE(Watchlist) // define RLMArray<Person>

// Implementations
@implementation User
@end // none needed

@implementation Watchlist
@end // none needed

Read data from realm :

RLMResults *watchlistDB = [Watchlist allObjects];
WatchlistDB = [realm_data objectAtIndex:index];
RLMArray *realm_array = WatchlistDB.watchlist;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!