简体   繁体   English

领域,使用swift在领域中查询对象

[英]Realm, query for objects in realm using swift

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. object.objectsWhere(“ parentId = 1”)等。 However the objectsWhere func is not available to me, I can however use allObjects or allObjectsInRealm just fine. 但是对象我无法使用func,但是我可以使用allObjects或allObjectsInRealm很好。

The project is iOS7 in swift, working in xcode 6.3 beta Couldn't find the method in stable xcode neither if that matters. 该项目是iOS7的快速版本,可以在xcode 6.3 beta中运行。即使如此,也无法在稳定的xcode中找到该方法。 Importing realm through Pods like such: 通过Pod导入领域,例如:

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. 编辑:在这种情况下,对象可以是扩展RLMObject的类或它在泛型func中的类型别名,但是没有泛型甚至不存在。

Realm uses Objective-C variadic arguments for the +[RLMObject objectsWhere:(NSString *)predicateFormat, ...] method, which aren't supported in Swift. Realm对+[RLMObject objectsWhere:(NSString *)predicateFormat, ...]方法使用了Objective-C可变参数,Swift不支持。 This is why Realm offers a file which adds a few Swift conveniences ( RLMSupport.swift ) which you can drag into your project. 这就是为什么Realm提供了一个文件,该文件添加了一些Swift便利功能( RLMSupport.swift ),您可以将其拖动到项目中。

Realm's installation instructions covers this and can be found here . Realm的安装说明涵盖了这一点,可以在这里找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM