领域,使用swift查询领域中的对象 [英] Realm, query for objects in realm using swift

查看:94
本文介绍了领域,使用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")等. 但是我无法使用func对象,但是我可以使用allObjects或allObjectsInRealm.

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

该项目是iOS7的快速版本,可以在xcode 6.3 beta中运行.无论如何,都无法在稳定的xcode中找到该方法.像这样通过Pod导入领域:

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'

有什么想法吗?

在这种情况下,对象可以是在通用函数中扩展RLMObject的类或它的类型别名,但是没有泛型甚至不存在.

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.

推荐答案

Realm为+[RLMObject objectsWhere:(NSString *)predicateFormat, ...]方法使用了Objective-C可变参数,Swift不支持.这就是为什么Realm提供了一个文件,该文件增加了一些Swift便利性( RLMSupport.swift ),您可以将其拖到您的项目中.

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的安装说明对此进行了介绍,可以在此处找到.

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

这篇关于领域,使用swift查询领域中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆