realm

Adding standalone-objects to a RealmList

人走茶凉 提交于 2019-12-09 10:20:33
问题 Is it possible to add standalone objects to a RealmList of an RealmObject already persisted in a realm? Well, I know it doesnt work, because I get NPEs at ( object.row.getIndex():RealmList:94 ) What I want to do is: mRealm.beginTransaction; contact.getEmails().add(new Email()); mRealm.commitTransaction; Because at that specific moment I dont have access to a Realm (well I could make it work, but I would have to rewrite some structures), for example: //In Activity Contact contact = Realm.where

Realm append data to a type List<t>

ⅰ亾dé卋堺 提交于 2019-12-09 07:33:30
问题 I'm trying to go through data and save it in my model, however whatever i do i keep getting the following error: Can't mutate a persisted array outside of a write transaction. . What am i doing wrong? i'm appending each match to the league however it does not seem to work? realm model class League: Object { dynamic var id: Int = 0 dynamic var name: String? = "" var matches = List<Match>() override class func primaryKey() -> String { return "id" } } class Match: Object { dynamic var matchId:

Realm, network operations, subscribing and observing on different threads with RxJava

独自空忆成欢 提交于 2019-12-09 07:18:03
问题 I need to : Fetch some data from an API on a background thread Display the data on the UI Save to Realm. fetchItemsFromServer().subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<ItemList>() { @Override public void call(ItemList items) { displayItems(items); try { realm.beginTransaction(); realm.copyToRealmOrUpdate(itemList); realm.commitTransaction(); Logger.v("Realm ", "Copied list object to realm"); } catch (Exception e) { Logger.e("Realm

Using Realm.io to store money values

吃可爱长大的小学妹 提交于 2019-12-09 03:32:14
问题 I'm starting to play with Realm.io in an Android app that I'm writing. In one of my data objects, I'm required to store a currency value. Previously I had stored the value internally as a BigDecimal value and then converted that too and from a double value when moving in and out of the database. I have always been told that it is a bad idea to store currency values in a double because of the way that they are handled. Unfortunately, Realm.io doesn't support the storage and retrieval of

Realm accessed from incorrect thread - Swift 3

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 03:16:51
问题 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? 回答1:

How can I use Realm with Swift 4?

流过昼夜 提交于 2019-12-09 02:49:29
问题 I'm trying to run my current project in the new Xcode 9 beta, but when I do so it says Module compiled with Swift 3.1 cannot be imported in Swift 4.0 . How can I solve this problem? I'm not using cocoapods. 回答1: Update : As of v2.10.1, released 2017-09-14, Realm's prebuilt binaries include frameworks built with Xcode 9 for Swift 3.2 and 4.0. It's no longer necessary to build them yourself. The information below remains relevant to anyone looking to use Realm with prerelease versions of Xcode

Realm Swift: how to catch RLMException?

感情迁移 提交于 2019-12-08 21:31:09
问题 I thought I was doing it correctly. let realm = try! Realm() do { try realm.write { realm.add(myObject) } } catch { print("something went wrong!") } But I'm still getting a crash instead of that print statement. I'm not interested in avoiding the exception (in this case I caused it deliberately by adding an object with an existing primary key) but I want to be able to catch it and prevent a crash no matter what. Is this possible, and if so, how? 回答1: Realm Swift throws Objective-C exceptions

Kotlin lazy usage

若如初见. 提交于 2019-12-08 19:23:25
问题 I'm currently using Realm in my application, and to make sure i manage Realm instances correctly, i introduced in my base Activity a variable like this: protected val realm: Realm by lazy { Realm.getDefaultInstance() } And then in onDestroy i do this: override fun onDestroy() { super.onDestroy() realm.close() } And then i realised this is a waste. If the current activity doesn't use realm, it will open and immediately close in onDestroy . So i updated to this: private var usedRealm = false

Class are being linked more than once in target

♀尐吖头ヾ 提交于 2019-12-08 18:48:43
问题 I have two targets app and appTests . Also I have class Wine and framework Realm and 'RealmSwift' which are linked to those two targets. There is no exception When I use class Wine in traget app . But when I want to run test like appTests.swift (22 lines) import UIKit import XCTest import RealmSwift class appTests: XCTestCase { func testRealmAdd() { NSFileManager.defaultManager().removeItemAtPath(Realm.defaultPath, error: nil) let realm = Realm() let wine = Wine() // when error occure wine

the realm is already in a write transaction

白昼怎懂夜的黑 提交于 2019-12-08 18:30:42
问题 the realm is already in a write transaction. How can i avoid this error? is there a way to check realm is in write traction? if realm is in write transaction then closed first then do other work. Now after getting this error "the realm is already in a write transaction." then other tasks connected with realm also not working. 回答1: The rule of thumb for Realm is only one write transaction open on an RLMRealm at any given time. You might need to reconsider your logic if you're hitting this