简体   繁体   中英

What is the correct way to use RLMResults in Swift?

I had an xcode project and I was using Swift and Objective c code. Now in other Swift project I want use a function to load and manage some data from realm databases like:

@objc func myData(_ allData: RLMResults<RLMObject>) -> [[AnyHashable]] {
...
}

If I remove the @objc reference I get the error:

Use of undeclared type 'RLMResults'

I have imported the realm sdk and sdk-swift, how can I declare this function in Swift? What could be the error?

Thanks!

I'm assuming you are using RealmSwift since you want to remove the @objc tag and and you are talking about a "Swift Project"

RLMResults is used for Obj-C version only. When using RealmSwift you need to use Results

Below you need to replace with the object result

import RealmSwift

func myData(_ allData: Results<Object>) -> [[AnyHashable]] {

}

Results is an auto-updating container type in Realm returned from object queries.

Results can be queried with the same predicates as List<Element> , and you can chain queries to further filter query results. Results always reflect the current state of the Realm on the current thread, including during write transactions on the current thread.

More information can be found HERE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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