realm

Convert from Realm Results to Array produce empty objects

放肆的年华 提交于 2019-12-06 13:18:08
When I try to convert from Results to Swift Array the properties are on the default values. So let's say I write a Request object like this: let realm = try! Realm() try! realm.write { realm.add(request, update: true) } Then when I'm reading them from Realm like this: let realm = try! Realm() let requestsFromRealm = realm.objects(Request.self) I got the results just fine. I need to convert the Results object to Array. I did it: let requests = Array(requestsFromRealm) The requests objects are there, but the properties are on the default values. The weird thing is, when I check the values on the

带你揭秘Shiro(一)

蹲街弑〆低调 提交于 2019-12-06 13:11:40
提到Shiro,不得不先介绍RBAC介绍 RBAC介绍:   RBAC是基于角色的访问控制(Role-Based Access Control )在 RBAC 中,权限与角色相关联,用户通过成为适当角色的成员而得到这些角色的权限。这就极大地简化了权限的管理。这样管理都是层级相互依赖的,权限赋予给角色,而把角色又赋予用户,这样的权限设计很清楚,管理起来很方便。 在RBAC模型里面,有3个基础组成部分,分别是:用户、角色和权限。 RBAC通过定义角色的权限,并对用户授予某个角色从而来控制用户的权限,实现了用户和权限的逻辑分离,极大地方便了权限的管理,在讲解之前,先介绍一些名词: User(用户):每个用户都有唯一的UID识别,并被授予不同的角色 Role(角色):不同角色具有不同的权限 Permission(权限):访问权限 用户-角色映射:用户和角色之间的映射关系 角色-权限映射:角色和权限之间的映射 权限管理:(包含两部分:用户认证,用户授权)   只要有用户参与的管理系统一般都有权限管理,权限管理实现对用户访问系统的控制,按照安全规则实现用户可以访问自己被授权的资源。 用户认证: 关键对象: subject:主体,理解为用户,可能是程序,都要去访问系统的资源,系统需要对subject进行身份认证。 principal:身份信息,通常是唯一的,一个主体还有多个身份信息

Swift how to declare realm results?

大城市里の小女人 提交于 2019-12-06 12:04:20
How to declare Results generic I want to declare it like global variable in UITableViewController and fill within viewDidLoad func Here's my code class ContactsController: UITableViewController { var contacts = Results<Contact>() override func viewDidLoad() { super.viewDidLoad() contacts = Domain.FetchContacts() } } But I get error Cannot invoke initializer for type 'Results' with no arguments How can I declare it? I declared results generic like this var contacts: Results<Contact>? = nil You can declare the contacts like this: var contacts: Results<Contact>! or var contacts: Results<Contact>?

Realm SyncUser.authenticate failed with Google's clientID and Facebook

故事扮演 提交于 2019-12-06 11:56:34
I'm using Google for authenticating, like following: let credential = Credential.google(token: "<SOME-HASH-HERE>.apps.googleusercontent.com") SyncUser.authenticate(with: credential, server: serverURL, timeout: 60) { [weak self] user, error in guard nil == error else { print("error while authenticating: \(error!)") return } … } It gives an error 400. After some debugging I found more info about the problem, but still not sure what is wrong with that. So response looks like this: { "invalid_params":[ { "name":"provider", "reason":"Unknown provider!" } ], "status":400, "type":"https://realm.io

How to update a list of objects in Realm DB Swift

折月煮酒 提交于 2019-12-06 11:33:58
I'm trying to find the right way to update a list in a Realm object. For example: class Person: Object { @objc dynamic var id: String = "" let children = List<Child>() } //Adding an item to the list func add(child: Child, _ completion: (DBError?) -> Void) { do { let ctx = try Realm() if let person = ctx.objects(Person.self).last { try ctx.write({ person.children.append(child) completion(nil) }) } catch { completion(DBError.unableToAccessDatabase) } } This seems to work for adding an element. So how do I update an individual element in the array as well as replace the whole array to ensure it

How to encode Realm's List<> type

蓝咒 提交于 2019-12-06 11:27:18
I am trying to encode my Realm database to JSON. Everything is working except the List<> encoding. So my question is, how would you encode List<> ? Because the List doesn't conform to Encodable neighter Decodable protocol. Right now I am doing this: @objcMembers class User: Object, Codable{ dynamic var name: String = "" let dogs = List<Dog>() private enum UserCodingKeys: String, CodingKey { case name case dogs } convenience init(name: String) { self.init() self.name = name } func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: UserCodingKeys.self) try container

How to set default realm path to App Groups directory

不羁的心 提交于 2019-12-06 11:12:43
I am trying to set the default Realm path to App Groups directory. let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("groups.prasanna.appName")! RLMRealm.setDefaultRealmPath(directory.absoluteString!) println(RLMRealm.defaultRealmPath()) The app crashes with the following error Terminating app due to uncaught exception 'RLMException', reason: 'open() failed: Operation not permitted' How do I fix this issue? jpsim the default realm path you're setting is your container directory. You'll have to append a file name for this to work: let

Obtaining contacts from content provider without duplicates or invalid contacts, and save to Realm

故事扮演 提交于 2019-12-06 09:53:19
问题 I have this code (thankfully provided by @EpicPandaForce) and I have problem with deletion. When I add new contact it works like a charm while when I delete contact (or number from that contact if there are two of them) it stays persisted in Realm. How can I get it working properly? realm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) { Contact realmContact = new Contact(); String filter = "" + ContactsContract.Contacts.HAS_PHONE_NUMBER + " > 0 and " +

Saving Data from CSV to Realm

我是研究僧i 提交于 2019-12-06 09:47:13
I have been creating a Dictionary App i have all words saved in the .csv file when app is run First Time, this method should save all the words to realm db but saving only few. Task java.util.concurrent.FutureTask@286858df rejected from io.realm.internal.async.RealmThreadPoolExecutor@273caff5[Running, pool size = 13, active threads = 13, queued tasks = 100, completed tasks = 1] realm = Realm.getDefaultInstance(); //adding to db satrt if (!(realm.isEmpty())) { Log.v("DB","already there!!"); } else { Log.v("DB","Not Found!!"); String csvFile = "longevity.csv"; BufferedReader br = null; String

Realm object as member is nil after saving

≡放荡痞女 提交于 2019-12-06 08:49:41
I'm facing an issue where a Realm object has another Realm object as member which is always nil after adding to the database. class MedPack: Object { dynamic var uuid = NSUUID().UUIDString dynamic var medicine: Medicine? convenience init(medicine: Medicine) { self.init() self.medicine = medicine } override static func primaryKey() -> String? { return "uuid" } } The reference to the object Medicine is always nil after adding. class Medicine: Object { var uuid = NSUUID().UUIDString var name: String? override static func primaryKey() -> String? { return "uuid" } } Creation of object let medPack =