realm

Realm accessed from incorrect thread

寵の児 提交于 2019-11-28 00:42:10
I'm using serial GCD queue to work with realm. Application crashes with Realm accessed from incorrect thread exception when GCD starts to switch threads for the queue. Is there any way to bind given realm with a thread using GCD API? Here's a quick example self.realmQueue = dispatch_queue_create("db", DISPATCH_QUEUE_SERIAL); __block RLMRealm *realm = nil; dispatch_async(self.realmQueue, ^{ realm = [RLMRealm realmWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"temp"]]; }); self.motionManager = [[CMMotionManager alloc] init]; self.motionManager.accelerometerUpdateInterval = 0

How can I set LIMIT in query in Realm?

早过忘川 提交于 2019-11-28 00:27:42
I have done R&D for limit in query with no success. There is one way with which to paginate data in Realm with sub list but no success with that. It shows duplicate value in it. Here is what I attempted for pagination. RealmResults<Person> mPersonData=RealmUtils.getAllPersonWithTagsDescending(); if (mPersonData != null) { int startPos=getAllPerson.size()-1; int endPos=mPersonData.size()-1; List<Person> newPersonData=mPersonData.subList(startPos,endPos); getAllPerson.addAll(newPersonData); mAdapter.notifyDataSetChanged(); } What am I doing wrong? You can use limit from Realm 5.6.0+. It looks

Complex sorting for search in realm, union of multiple RealmResults

为君一笑 提交于 2019-11-28 00:26:08
I replaced sqlite with realm in my open source Linux Command Library project. Everything went fine so far, but now I'm facing a problem. I'm using a RealmBaseAdapter to display all the commands in a ListView with an search interface. For a search the realm sniped below orders the results like this: Query: test result: l2 test rc test test test parm RealmResults<Command> commands = mRealm.where(Command.class).contains("name", query).findAll(); mAdapter.updateRealmResults(commands); With the old sqlite logic the order was like this: result: test test parm l2 test rc test return

How do I set a auto increment key in Realm?

余生长醉 提交于 2019-11-27 20:40:05
问题 I have a unique msgid for each ChatData object. @interface ChatData : RLMObject @property NSInteger msgid; .... @end But each time I create a new object I have to query all objects and get the last msgid. RLMArray *all = [[ChatData allObjects] arraySortedByProperty:@"msgid" ascending:YES]; ChatData *last = [all lastObject]; ChatData *newData = [[ChataData alloc]init]; newData.msgid = last.msgid+1; Is there an efficient way to replace this implementation? 回答1: Realm doesn't have auto increment

Retrofit + RealmList + Gson stuck in a loop until out of memory

一笑奈何 提交于 2019-11-27 18:44:10
问题 I'm trying to user Retrofit + Realm + Gson, but when the RealmList is used the app get stuck. If I remove the RealmList objects everything work's fine, but I need the object list. Logcat: (32099): Background sticky concurrent mark sweep GC freed 278516(15MB) AllocSpace objects, 0(0B) LOS objects, 25% free, 23MB/31MB, paused 2.533ms total 1.049s (32099): Background partial concurrent mark sweep GC freed 137132(8MB) AllocSpace objects, 0(0B) LOS objects, 40% free, 23MB/39MB, paused 4.211ms

RLMException, Migration is required for object type

旧街凉风 提交于 2019-11-27 12:50:23
问题 I have an object NotSureItem in which I have three properties title whose name is renamed from text and textDescription which I had added later and a dateTime property. Now when I am going to run my app it crashes when I want to add something to these properties. It shows following statements. 'Migration is required for object type 'NotSureItem' due to the following errors: - Property 'text' is missing from latest object model. - Property 'title' has been added to latest object model. -

Storing an array of strings using Realm's RLMArray

独自空忆成欢 提交于 2019-11-27 12:27:20
问题 Does anyone know how you can use Realm to store an array of strings? I'm trying to map the following response into Realm correctly: "zoneInfo": { "tariffInfoLines": [ "In this city you pay per minute." ] } We have a zoneInfo object that contains a tariffInfoLines array. This tariffInfoLines array contains strings. In Realm there are two different variable types for storing data. The first is RLMObject which allows your standard NSString, int, long etc. The second type is RLMArray, which is

Realm & React Native - Best practice to implement auto-updates?

坚强是说给别人听的谎言 提交于 2019-11-27 12:26:29
问题 What are the best practices/patterns make realm a reactive datasource in a react native app? Especially for presentational and container components pattern? Here is an example which I'd like to make reactive: Realm with React Native The docs on auto-updates/change-events are a bit thin and the official example does not make use of this feature (to my knowledge). 回答1: You can make your example reactive by subscribing to events and updating the ui when you receive a change event. Right now

RealmSwift: Convert Results to Swift Array

守給你的承諾、 提交于 2019-11-27 09:41:32
问题 What I want to implement: class func getSomeObject() -> [SomeObject]? { let objects = Realm().objects(SomeObject) return objects.count > 0 ? objects : nil } How can I return object as [SomeObject] instead if Results ? 回答1: Weird, the answer is very straight forward. Here is how I do it: let array = Array(results) // la fin 回答2: If you absolutely must convert your Results to Array , keep in mind there's a performance and memory overhead, since Results is lazy. But you can do it in one line, as

Using enum as property of Realm model

耗尽温柔 提交于 2019-11-27 09:39:40
问题 Is it possible to use an Enum as a property for my model? I currently have a class like this: class Checkin: RLMObject { dynamic var id: Int = 0 dynamic var kind: String = "checked_in" var kindEnum: Kind = .CheckedIn { willSet { self.kind = newValue.rawValue } } enum Kind: String { case CheckedIn = "checked_in" case EnRoute = "en_route" case DroppedOff = "dropped_off" } .... } It works okay, but I'd like to be able to have the kind property be the Enum and have Realm automatically call