realm

Realm append data to a type List<t>

六眼飞鱼酱① 提交于 2019-12-03 08:53:13
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: Int = 0 dynamic var date: NSDate? dynamic var homeName: String? = "" dynamic var awayName: String? = ""

Why does Realm use RealmOptional&lt;Int&gt; rather than Int? for optional properties?

匿名 (未验证) 提交于 2019-12-03 08:50:26
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 getters and setters, your properties must be

How to perform Realm count query

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I do a count query on Realm? for example this is my model class Dog: Object { dynamic var name = "" } class Person: Object { dynamic var name = "" let dogs = List<Dog>() } I want to fetch all persons with at least one dog something like Realm().objects(Person).filter("dogs.@count > 0") but @count isn't supported as i understand 回答1: Yes, Realm still does not support .@count query. You can work around that you modify the Person model to have a count property. Then you update the count property when you append a dog object to the dogs

How to update the values in Table using Realm android?

假装没事ソ 提交于 2019-12-03 08:37:57
I have table say Student .I want to updated the values in the table and it does not have any primary key. I am using Realm Database for the same. Assume You have VisitingCardPOJO you can find element depending on "no" use findFirst() if you want to update only first element or you can use findAll() you get list of record then you update same way below using for loop public void updateNewCard(Realm realm, VisitingCardPOJO card) { VisitingCardPOJO toEdit = realm.where(VisitingCardPOJO.class) .equalTo("no", card.getNo()).findFirst(); realm.beginTransaction(); toEdit.setName(card.getName());

SBT is unable to find credentials when attempting to download from an Artifactory virtual repo

匿名 (未验证) 提交于 2019-12-03 08:30:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to run SBT behind a corporate firewall. Another team has configured an Artifactory proxy. This proxy works fine with anonymous access switched on, but when we make it require a password thinks start to go wrong. When I run SBT on my workstation I get the following error: [error] Unable to find credentials for [Artifactory Realm @ coderepo.xxx.amrs.bigco.com] The result of this is that I cannot bootstrap sbt: [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] :: UNRESOLVED DEPENDENCIES :: [warn] ::::::::::::::::::::::::::

Can I serialize a RealmObject to JSON or to NSDictionary in Realm for Swift?

微笑、不失礼 提交于 2019-12-03 06:26:00
问题 I'm testing Realm, but I cant find a easy way to convert my object to JSON. I need to push the data to my REST interface. How can I do it using swift? class Dog: Object { dynamic var name = "" } class Person : Object { dynamic var name = "" let dogs = List<Dog>() } I'm trying something like this, but I can't iterate unknown objects (List) extension Object { func toDictionary() -> NSDictionary { let props = self.objectSchema.properties.map { $0.name } var dicProps = self

Swift Remove Object from Realm

倖福魔咒の 提交于 2019-12-03 06:08:52
I have Realm Object that save list from the JSON Response. But now i need to remove the object if the object is not on the list again from JSON. How i do that? This is my init for realm func listItems (dic : Array<[String:AnyObject]>) -> Array<Items> { let items : NSMutableArray = NSMutableArray() let realm = try! Realm() for itemDic in dic { let item = Items.init(item: itemDic) try! realm.write { realm.add(item, update: true) } items.addObject(item) } return NSArray(items) as! Array<Items> } fel1xw imagine your Items object has an id property, and you want to remove the old values not

Update statement in Realm android

风格不统一 提交于 2019-12-03 05:48:11
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 j_gonfer 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 method will update the object automatically without duplicate objects :) More info: copyToRealmOrUpdate(

iOS Realm Filter objects in a list of a relationship

怎甘沉沦 提交于 2019-12-03 05:24:51
I have three objects nested via lists like this: class Canteen: Object { dynamic var name: String? let lines = List<Line>() } class Line: Object { dynamic var name: String? let meals = List<Meal>() } class Meal: Object { dynamic var name: String? dynamic var vegan: Bool = false } Getting all canteens with all the lines and meals is no problem. What im doing right now is this: let predicate = NSPredicate(format: "name == %@", selectedCanteenType.rawValue) canteens = realm.objects(Canteen).filter(predicate) But now i only need the meals which are vegan. So im looking to get the selected canteen

How to make a nested query in Realm?

帅比萌擦擦* 提交于 2019-12-03 05:24:07
I have two realms: public class ChatRealm extends RealmObject { private String id; private RealmList<UserRealm> users; } public class UserRealm extends RealmObject { private String id; private String username; } I have an User id and I want to know which chats he is participating in. I have check the Realm documentation and couldn't find how to do this type of queries. How can I get the results I want using a Realm query? How about link query in documentation? There is an example: RealmResults<ChatRealm> contacts = realm.where(ChatRealm.class).equalTo("users.id", "some id").findAll(); 来源: