realm

How to create a background thread with a looper

拜拜、爱过 提交于 2021-02-07 12:35:48
问题 Can someone please share the implementation of a background thread with a Looper that i can pass to the subscribeOn(AndroidScheduler.from(/ backgroundThreadWithLooper /)). I need this because i am trying to implement a DBService class that runs all of its operations in the background while still getting live objects updates. So when i apply an addChangeListener, an exception is thrown: java.lang.IllegalStateException: Your Realm is opened from a thread without a Looper. Async queries need a

What is the right way to present data from Realm in SwiftUI List

蓝咒 提交于 2021-02-05 07:00:34
问题 I’m trying to fetch all of the items from Realm and display them in a SwiftUI List but I keep getting an error. In a UIKit/Realm application, I would just create a Results variable to store all of the items from Realm then, I would fetch items in the viewDidLoad method and assign them to the variable. I'm trying to do the same thing in SwiftUI but I'm not sure how to structure my code, I keep getting an error saying that my Realm model should conform to the StringProtocol , I'm pretty sure

RETROFIT POST Realm object

江枫思渺然 提交于 2021-02-04 13:13:05
问题 I have the following RETROFIT API: @POST("/payments") Observable<Response> saveCreditCard(@Body CreditCard creditCard) CreditCard is a RealmObject . When I try to use my API method: CreditCard card = realm.createObject(CreditCard.class); card.setWhateverField(...); ... mApi.saveCreditCard(card) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(...); I get the following error: > retrofit.RetrofitError: com.fasterxml.jackson.databind.JsonMappingException: Realm

How to have single connection for each device in MongoDB Atlas?

谁都会走 提交于 2021-01-29 22:12:40
问题 I have an Android that uses firebase for authentication and MongoDb as a backend, I'm currently on the M0 cluster where the connection limit is 500. I use the Stitch API. When I use app from my device the number of connections increases from 4 to 8. I think initial 4 connections are by default so I don't mind that but I'm really concerned about such a jump in number of connections from a single device. PS. I tried having StitchAppClient and RemoteMongoClient in common class, so that there

How to find sum for each category in an array?

孤者浪人 提交于 2021-01-29 20:22:27
问题 I have an array that contains multiple items. This is a Realm array. It contains data in the following structure: Results<Entry> <0x7ff04840e1a0> ( [0] Entry { name = Salary; amount = 40000; date = 2020-03-18 16:00:00 +0000; category = Main Incomes; entryType = Income; }, [1] Entry { name = Diff; amount = -500; date = 2020-04-18 16:00:00 +0000; category = Misc; entryType = Expense; }, [2] Entry { name = Cat Food; amount = -399; date = 2020-04-18 16:00:00 +0000; category = Animals; entryType =

How to find sum for each category in an array?

前提是你 提交于 2021-01-29 17:20:54
问题 I have an array that contains multiple items. This is a Realm array. It contains data in the following structure: Results<Entry> <0x7ff04840e1a0> ( [0] Entry { name = Salary; amount = 40000; date = 2020-03-18 16:00:00 +0000; category = Main Incomes; entryType = Income; }, [1] Entry { name = Diff; amount = -500; date = 2020-04-18 16:00:00 +0000; category = Misc; entryType = Expense; }, [2] Entry { name = Cat Food; amount = -399; date = 2020-04-18 16:00:00 +0000; category = Animals; entryType =

Realm - how to find a string in a List

喜夏-厌秋 提交于 2021-01-29 16:57:33
问题 Here's my object: class Cat: Object { let toys = List<String>() } How can I find a toy in the toys array and delete it? if let foundToy = cat.toys.filter(???).first { try! realm.write { realm.delete(foundToy) } } 回答1: If you are keeping an array of distinct String (i.e., the toys array doesn't contain duplicates), you can just delete the first String found: if let toyIndex = cat.toys.firstIndex(of: toyNameToBeDeleted) { try! realm.write { cat.toys.remove(at: toyIndex) } } If you are trying to

What does error “Expression type '@lvalue String?' is ambiguous without more context” mean?

此生再无相见时 提交于 2021-01-29 10:51:15
问题 In a TableView Controller, I have multiple UITextFields that allow users to input some information and use Realm to save data from users' input. I use the following ways to add the data but I got the error saying "Expression type '@lvalue String?' is ambiguous without more context" import UIKit import RealmSwift class NewIdeaCreation: UITableViewController, UITextFieldDelegate { let realm = try! Realm() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading

realm updating data + DispatchQueue

我们两清 提交于 2021-01-29 05:17:04
问题 I have update DataBase in background. My data can contain ~2000 items and it take time to update. func updateData(items: [JSON], _ complete:@escaping() -> Void) { DispatchQueue.global(qos: .userInitiated).async { let currentModels = EgrnModel.getAllModels() var newModels: [EgrnModel] = [] var toDelete: [EgrnModel] = [] for model in currentModels { let contain = items.contains(where: {$0["id"].intValue == model.id}) if !contain { toDelete.append(model) } } let realm = try! Realm() try! realm

How to connect to MongoDB from iOS (Swift)

心不动则不痛 提交于 2021-01-28 14:10:23
问题 I have developed an iOS application using RealmSwift. This works fine so far. Now, as I'm getting closer to publishing into App Store, I wanted to set up some cloud configuration to be able to connect to a cloud database, but I just got totally confused. A couple of weeks ago I saw Realm Cloud as an option. Now I only see MongoDB Realm - or something like that. I digged into a bit, and found that there are three components: Realm DB, Realm Sync and Mongo DB Atlas. If my understanding is