realm

How to use Realm with SwiftUI

会有一股神秘感。 提交于 2019-12-03 15:17:58
问题 I have been trying to figure out how to use Realm with SwiftUI. The problem is that SwiftUI and Realm both have a List type. When you import SwiftUI into your Realm model to make the class a BindableObject and try to create a Realm List property there is an error. Is it possible to use an instance of the Realm object model and make it a BindableObject in SwiftUI? 回答1: Sure, it's very simple, use the module identifier as prefix like this : let members = RealmSwift.List<Member>() Now to the

Update statement in Realm android

柔情痞子 提交于 2019-12-03 15:11:40
问题 How should i update a already existing value using realm DB in android? I have been trying to update it but it is adding as a new value only not overwritting it 回答1: Another way to update an existing object with all its fields in your Realm DB is using the method realm.copyToRealmOrUpdate() : Object obj = new Object(); obj.setField1(field1); obj.setField2(field2); realm.beginTransaction(); realm.copyToRealmOrUpdate(obj); realm.commitTransaction(); If your object has a Primary Key , this

Android's realm.io how to sync with server side MySQL DB

你说的曾经没有我的故事 提交于 2019-12-03 14:45:38
I am working on an Android app using realm db as my local db, how do I sync my records in realm with my server side MySQL db? Alexander Update from 27 Septermber 2016: Realm now fully supports synchronizing data against Realm Object Server. More details are available here . 19 June 2016 There is no such way - the Realm doesn't have such mechanisms, and it is logical. You mix different approaches - syncing data and storing locally (the mission of Realm, SQLite and other Android mobile DBs). You can do it by your own custom implementation ( like in the tutorial ), or using by SyncAdapter . As

Order by multiple properties using Realm

南楼画角 提交于 2019-12-03 14:41:23
问题 How can I order my Realm results using multiple properties? I'm sorting them first using one property like this: allShows = Show.allObjects().sortedResultsUsingProperty("dateStart", ascending: true) But now I also want to do a secondary sort by another property "timeStart". I tried like this: allShows = Show.allObjects().sortedResultsUsingProperty("dateStart", ascending: true).sortedResultsUsingProperty("timeStart", ascending: true) This will just make the results sorted only by the second

Xcode unable to find strip-frameworks.sh directory

拜拜、爱过 提交于 2019-12-03 14:33:16
问题 I recently update Xcode to Version 7.1, which included Swift 2.1. I installed Swift 2.1 with no troubles. After attempting to run my project, I realized that I needed to grab the latest version of Realm, since the previous version did not support Swift 2.1. I deleted the old frameworks and imported Realm 0.96.2. Whenever I run, I now get this error: bash: /Users/userName/Library/Developer/Xcode/DerivedData/appName-ghiroqitgsbvfhdqxsscyokyoouz/Build/Products/Debug-iphoneos/appName.app

How do you compact a Realm DB on iOS?

强颜欢笑 提交于 2019-12-03 13:27:13
I'd like to compact a Realm instance on iOS periodically to recover space. I think the process is to copy the db to a temporary location, then copy it back and use the new default.realm file. My problem is Realm() acts like a singleton and recycles objects so I can't really close it and tell it to open the new default.realm file. The docs here ( https://realm.io/docs/objc/latest/api/Classes/RLMRealm.html ) suggest I wrap all the Realm() calls in autorelease { } but it can't be this complicated. It can be indeed tricky to completely tear down all retrieved model accessors, but there is

Realm notification token on background thread

偶尔善良 提交于 2019-12-03 13:10:19
问题 I was trying to fetch realm data on the background thread and add a notification block (iOS, Swift). Basic example: func initNotificationToken() { DispatchQueue.global(qos: .background).async { let realm = try! Realm() results = self.getRealmResults() notificationToken = results.addNotificationBlock { [weak self] (changes: RealmCollectionChange) in switch changes { case .initial: self?.initializeDataSource() break case .update(_, let deletions, let insertions, let modifications): self?

Adding standalone-objects to a RealmList

最后都变了- 提交于 2019-12-03 12:55:45
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(Contact.class).equalsTo("name","pete").findAll().first(); mRealm.beginTransaction; UpdateHelper.update

Is closing and reopening Realm instances bad for performance?

你离开我真会死。 提交于 2019-12-03 12:53:18
问题 When using SQLite I usually have a single SQLiteOpenHelper instance per application and I never ever close it, since its database is used continuously by many other classes and closing/reopening it would be slower and more complicated. Now I'm toying with Realm and I'm planning to access Realm instances only from Data Access Objects. Every call will be made from a worker thread. I've been reading the examples and they usually call getInstance/close per Activity or background task. Since Realm

Use pre-populated databases with Realm

不问归期 提交于 2019-12-03 12:51:58
How could we convert SQLite database to a Realm database? Is there any way to use pre-populated databases with Realm on Android? Currently there is no way to automatically convert a SQLite database to a Realm database, you would have to manually read all data from the SQLite database and insert them into Realm. An alternative could be the Realm browser that might make this easier, but it is currently available for MacOS X only. You can read more here: https://github.com/realm/realm-java/issues/435 For the second part: As Realm databases are just a single file so you can easily add a pre