realm

How do I set a auto increment key in Realm?

て烟熏妆下的殇ゞ 提交于 2019-11-30 03:14:18
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? Realm doesn't have auto increment behavior, so you'll need to manage that yourself. A question I'd encourage you to ask yourself about your

Realm accessed from incorrect thread - again

本小妞迷上赌 提交于 2019-11-30 03:04:22
问题 I noticed many problems with accessing realm object, and I thought that my solution would be solving that. So I have written simple helping method like this: public func write(completion: @escaping (Realm) -> ()) { DispatchQueue(label: "realm").async { if let realm = try? Realm() { try? realm.write { completion(realm) } } } } I thought that completion block will be fine, because everytime I write object or update it, I use this method above. Unfortunately I'm getting error: libc++abi.dylib:

How to install realm as a gradle dependency?

混江龙づ霸主 提交于 2019-11-30 02:34:57
问题 I am completely new to realm. I want to use realm db in my android project. I have gone through the official Realm documentation. I need to set up realm in my android project. For that I have added the gradle dependancy as buildscript { repositories { jcenter() } dependencies { classpath "io.realm:realm-gradle-plugin:0.88.2" } } apply plugin: 'realm-android' This is what they have given in documentation. But this doesn't work for me. It gives error saying Plugin with id 'realm-android' not

Realm: Results<T> als List<T>

南楼画角 提交于 2019-11-30 01:50:42
问题 Is it possible to convert Results<T> to List<T> or shouldn't I do this? In my case I have method that has List as a parameter. I want to call this method with fetched objects ( Results<T> ) and with computed objects ( List<T> ) 回答1: Results and List implement CollectionType and RealmCollectionType . The latter is a specialization of the former protocol, which allows you to efficiently use aggregation functions and filter & sort entries. Almost no method in Realm Swift make strong assumptions

Android Realm initialization in project

倖福魔咒の 提交于 2019-11-30 01:38:34
问题 As seen in the official documentation on how to use Realm // Initialize Realm Realm.init(context); // Get a Realm instance for this thread Realm realm = Realm.getDefaultInstance(); I added dependencie to my project classpath "io.realm:realm-gradle-plugin:2.0.2" I can use this library normally but static method init apparently does not exist . Can someone post an example of how to initialize and save example object to database using this library? There's really not too many tutorials and the

Realm - Can't create object with existing primary key value

安稳与你 提交于 2019-11-30 01:26:30
问题 I have a object Person with many dogs. App has separate page where it shows just dogs and other page where it shows person's dogs My model is as follows class Person: Object { dynamic var id = 0 let dogs= List<Dog>() override static func primaryKey() -> String? { return "id" } } class Dog: Object { dynamic var id = 0 dynamic var name = "" override static func primaryKey() -> String? { return "id" } } I have persons stored in Realm. Person has detail page where we fetch and show his dogs. If

This Realm instance has already been closed, making it unusable + RxJava

孤街醉人 提交于 2019-11-29 22:57:46
问题 First of all i manage realm instance by Repository class: public class RealmRepository { private Lock lock; protected RealmRepository() { lock = new ReentrantLock(); } public <T> T execute(Executor<T> executor) { Realm realm = null; try { lock.lock(); realm = Realm.getDefaultInstance(); return executor.execute(realm); } finally { if (realm != null && !realm.isClosed()) { realm.close(); } lock.unlock(); } } public interface Executor<T> { T execute(Realm realm); } } And the only class that

realm mobile platform, how to connect while offline?

北慕城南 提交于 2019-11-29 22:29:33
问题 the new realm mobile platform is advertised with offline support, however most tutorials does not show how that works in the examples... for example, in their todo app example this is the code used to connect to the server database SyncUser.logIn(with: .usernamePassword(username: username, password: password, register: false), server: URL(string: "http://127.0.0.1:9080")!) { user, error in guard let user = user else { fatalError(String(describing: error)) } DispatchQueue.main.async { // Open

GitLab CI: iOS project issue (permission denied)

≡放荡痞女 提交于 2019-11-29 18:11:30
Trying GitLab CI for my iOS project, I follow this , this and this tutorial. Two questions: What is wrong with my gitlab-runner (with "shell" registration) since GitLab CI throws the following error: Running with gitlab-runner 11.9.0 (692ae235) on MyApp runner with shell DsaBC-oQ Using Shell executor... Running on MyComputer.network.provider... mkdir: /Users/myusername/builds/DsaBC-oQ/0/username/myproj.tmp: Permission denied mkdir: /Users/myusername/builds/DsaBC-oQ/0/username/myproj.tmp: Permission denied ERROR: Job failed: exit status 1 Some people say to use "sudo" for the gitlab-runner

How to delete a class from realm file

允我心安 提交于 2019-11-29 17:14:55
My default Realm has several classes. I want to completely remove all references and delete all data for one of the classes. How can I do this? When I remove the class from my application, the class is still listed when I open the file in Realm Browser. To completely remove a class from your Realm file you'll want to do two things: Remove the class from your application. Have your migration block call Migration.deleteData(_:) to remove all references to the class from the Realm. 来源: https://stackoverflow.com/questions/36717796/how-to-delete-a-class-from-realm-file