realm

Android Realm ChangeListener not being triggered

血红的双手。 提交于 2019-12-01 07:39:44
I've got a Realm results change listener that isn't being triggered, here's the code: final RealmResults<LogEntry> entries = realm.where(LogEntry.class).findAll(); entries.addChangeListener(new RealmChangeListener<RealmResults<LogEntry>>() { @Override public void onChange(RealmResults<LogEntry> results) { Log.v("Testing", "The size is: " + results.size()); } }); There is definitely new stuff being added, I have a log on the realm insertion printing out the new size of the table, yet for some reason the change listener does nothing? Am I missing something here, it seems identical to the docs.

Realm accessed from incorrect thread - Swift 3

孤人 提交于 2019-12-01 07:33:09
At the top of my UITableViewController is the following: let queue = DispatchQueue(label: "background") When a task is deleted, the following executes: self.queue.async { autoreleasepool { let realm = try! Realm() realm.beginWrite() realm.delete(task) do { try realm.commitWrite() } catch let error { self.presentError() } } } And then I receive the error terminating with uncaught exception of type realm::IncorrectThreadException: Realm accessed from incorrect thread. How could I fix this? Samantha It seems like the write is happening on a different thread than the object was originally accessed

Alamofire, Objectmapper, Realm: Nested Objects

风流意气都作罢 提交于 2019-12-01 07:32:12
I'm using Alamofire, Objectmapper, Realm and everything is working beside one thing: I can't map nested objects. class Voting: Object, Mappable { dynamic var votingID: String = "" dynamic var question: String = "" var votingOptions = List<VotingOption>() required convenience init?(_ map: Map) { self.init() } func mapping(map: Map) { votingID <- map["id"] question <- map["question"] votingOptions <- map["votingOptions"] } override class func primaryKey() -> String { return "votingID" } } class VotingOption: Object, Mappable{ dynamic var optionID: String = "" dynamic var text: String = ""

Realm String greaterThan

别说谁变了你拦得住时间么 提交于 2019-12-01 07:31:11
问题 Is there any way to find all (or just the next) RealmObject s with Strings lexicographically greater than the target? Something like MyEntry next = realm.where(MyEntry.class) .greaterThan("name", current) .findAllSorted("name") .first(); which did not work, because greaterThan is not implemented for String s. 回答1: As a non-db-workaround, you can use List<MyEntry> l = realm.where(MyEntry.class) .findAllSorted("name"); int pos = l.indexOf(entryWithName); MyEntry next = l.get((pos+1)%l.size());

Share Realm Data with WatchOS

二次信任 提交于 2019-12-01 06:22:57
In my project I want to use one Realm Database with my iOS 10 application and my watchOs 3 application at the same time. So what I did was adding the frameworks to the embedded binaries for the three different targets. This happened to work very well but the watchKit extension doesn't seem to recognize the objects that I created within the iOS environment. How is it possible to have a shared Realm Database between those two devices? TiM Update: Okay, thanks to chrisamanse 's heads-up, I did some more research on this. It turns out that App Groups are no longer possible on watchOS 2. Watch apps

Realm for Android with Kotlin - Cannot change Dependencies of Configuration after it has been included in dependency resolution

僤鯓⒐⒋嵵緔 提交于 2019-12-01 06:19:46
I am trying to get Realm to work in my project. I have Kotlin with version 1.2.51 and Instant Run disabled. In my project build.gradle file I added the following dependency: classpath "io.realm:realm-gradle-plugin:5.4.0" In my App build.gradle file I applied the Realm plugin as explained in the tutorial: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: 'realm-android' When I am trying to build the project, I get the following error: org.gradle.api.ProjectConfigurationException: A problem

Android Realm - Accessing Realm Object from Service

北慕城南 提交于 2019-12-01 06:18:44
I have a realm object that is created in my activity. I need to be able to access this object within a service that I created. However I'm getting the error when creating the Realm object within the service mRealm = Realm.getInstance(getApplicationContext()); java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created Now I understand this means that because the realm object was created on my activity, I cannot access it from a background thread. However, I'm not finding an easy way around this other than creating my

Android Realm - Accessing Realm Object from Service

徘徊边缘 提交于 2019-12-01 06:02:17
问题 I have a realm object that is created in my activity. I need to be able to access this object within a service that I created. However I'm getting the error when creating the Realm object within the service mRealm = Realm.getInstance(getApplicationContext()); java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created Now I understand this means that because the realm object was created on my activity, I cannot access

Android, using Realm singleton in Application

北城余情 提交于 2019-12-01 05:17:28
I'm new to Realm, I'm wondering whether it's good practice to just have one Realm instance in Application object, use it across all cases needed in the app, and only close it in onDestroy of the Application class. Thanks There is nothing inherently wrong with keeping the Realm on the UI thread open and not closing it (note there is no OnDestroy on Application ) However you should keep the following in mind: 1) Realm can handle the process getting killed just fine, which means that forgetting to close Realm is not dangerous to your data. 2) Not closing Realm when the app goes in the background

Why does Realm use RealmOptional<Int> rather than Int? for optional properties?

时光怂恿深爱的人放手 提交于 2019-12-01 05:08:56
问题 Realm's documentation on optional properties states: String , NSDate , and NSData properties can be declared as optional or non-optional using the standard Swift syntax. Optional numeric types are declared using RealmOptional. Why do numeric types use the non-standard RealmOptional rather than Swift's built-in optional syntax? 回答1: Realm model classes automatically implement getters and setters for your persisted properties that access the underlying database data. In order to provide these