境界:结果T als List< T> [英] Realm: Results<T> als List<T>

查看:91
本文介绍了境界:结果T als List< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将Results<T>转换为List<T>?或者我不应该这样做吗?

Is it possible to convert Results<T> to List<T> or shouldn't I do this?

就我而言,我有一个以List为参数的方法.我想用获取的对象(Results<T>)和计算的对象(List<T>)调用此方法

In my case I have method that has List as a parameter. I want to call this method with fetched objects (Results<T>) and with computed objects (List<T>)

推荐答案

ResultsList实现CollectionTypeRealmCollectionType.后者是前一种协议的一种特殊功能,可让您有效地使用聚合功能并进行过滤和过滤.对条目进行排序.

Results and List implement CollectionType and RealmCollectionType. The latter is a specialization of the former protocol, which allows you to efficiently use aggregation functions and filter & sort entries.

在Realm Swift中,几乎没有方法对集合的类型做出强有力的假设.他们只是期望SequenceType,它是前一个CollectionType的概括.对于您自己的方法,建议使用相同的方法.您可以通过如下所示进行声明来达到目的.

Almost no method in Realm Swift make strong assumptions about the type of the collection. They just expect a SequenceType which is a generalization of the former CollectionType. For your own method, I'd recommend to go the same way. You can reach that by declaring it like shown below.

func foo<T, S: SequenceType where S.Generator.Element == T>(objects: S) { … }

这篇关于境界:结果T als List&lt; T&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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