Realm, query for objects in realm using swift

断了今生、忘了曾经 提交于 2020-03-22 09:17:05

问题


I'm working on a swift project and when I look around the internet in most cases you can query for an object like so:

object.objectsWhere("parentId = 1") or such. However the objectsWhere func is not available to me, I can however use allObjects or allObjectsInRealm just fine.

The project is iOS7 in swift, working in xcode 6.3 beta Couldn't find the method in stable xcode neither if that matters. Importing realm through Pods like such:

pod 'Realm'

Any thoughts?

Edit: object in this case could be the class extending RLMObject or a typealias of it in a generic func, but it's not even there without generics.


回答1:


Realm uses Objective-C variadic arguments for the +[RLMObject objectsWhere:(NSString *)predicateFormat, ...] method, which aren't supported in Swift. This is why Realm offers a file which adds a few Swift conveniences (RLMSupport.swift) which you can drag into your project.

Realm's installation instructions covers this and can be found here.



来源:https://stackoverflow.com/questions/29692820/realm-query-for-objects-in-realm-using-swift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!