Michael
Michael

Reputation: 1030

RealmSwift v0.96 - Use of undeclared type "Results"

I updated my RealmSwift to version 0.96 and now get an error when I want to write an extension for Result:

Use of undeclared type "Results" 

that's what I want did before. There were some changes about Result and List in the latest updates but I don't know how to change my code:

extension Results {
    func toArray<T>(ofType: T.Type) -> [T] {
        var array = [T]()
        for var i = 0; i < count; i++ {
            if let result = self[i] as? T {
                array.append(result)
            }
        }

        return array
    }
}

Upvotes: 1

Views: 1734

Answers (1)

Wim Haanstra
Wim Haanstra

Reputation: 5998

Are you using CocoaPods with use_frameworks!, or do you use your bridging header file (or some other way to include RealmSwift).

If you are using CocoaPods with use_frameworks!, make sure you include the reference to RealmSwift in your file defining the extension.

import RealmSwift

EDIT: Yup, this works for me:

import RealmSwift

extension Results {
    func wow() -> String {
        return "test"
    }
}

Also, converting your Results to an array can be done much easier, more like this:

var someObjects = realm.objects(SomeObjectType).map { $0 }

This returns an [SomeObjectType] type of array.

Upvotes: 2

Related Questions