Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot convert value of type<> to expected arguments RLMResults<RLMObjects> #1594

Closed
superandrew opened this issue Oct 2, 2016 · 6 comments

Comments

@superandrew
Copy link

superandrew commented Oct 2, 2016

Hi, not sure this is an issue.

Running Charts with realm, trying to copy in swift what is setup in objc in the demo project, I have this error:

let results = realm.objects(MinMaxMeasure)

let set: RealmLineDataSet = RealmLineDataSet(results: results, xValueField: "Myvalue", yValueField: "MyValue", label: "MySeries")

the error says:

cannot convert value of type Results<MinMaxMeasure> to expected arguments RLMResults<RLMObjects>

I get the point, but cannot understand if this depends from a wrong version of swift, a bug, or something I am not doing properly.

Also, If I instantiate a RLMRealm instead of a Realm Object, I get no compilation errors, however I have a EXC_BAD_ACCESS on Realm.verify inside the Realm framework.

I am trying to run in a XCode 8 /Swift3 project.

screen shot 2016-10-02 at 14 52 00

@superandrew
Copy link
Author

So I thint I am using the objective-c realm instead of realmswift, is that correct? Is my setup wrong? Is RealmCharts able to use RealmSwift? And if so, how?

Thank you very much for helping.

@superandrew
Copy link
Author

superandrew commented Oct 2, 2016

Just in case anyone stumbles in a similar issue: I was instantiating Realm this way:

let realm = try! RLMRealm()

instead of

let realm = try! RLMRealm.default()

I still don't understand why Charts cannot use RealmSwift or if there is something in my setup which is wrong.

Now it works but it fails trying to cast MinMaxMeasure to RLMObjects inside

internal func buildCache()
    {
        guard let results = _results else { return }

         _cache.removeAll()
         _cache.reserveCapacity(Int(results.count))

         var xValue: Double = 0.0

         let iterator = NSFastEnumerationIterator(results)
         while let e = iterator.next()
         {
             _cache.append(buildEntryFromResultObject(e as! RLMObject, x: xValue))
             xValue += 1.0
         }
     }

I still don't understand how to build a RealmLineDataSet, which I currently am instantiating like this:

let set = RealmLineDataSet(realm: realm, modelName: "MinMaxMeasure", resultsWhere: "mac ='00158D000046CD83'", xValueField: "timestamp", yValueField: "iPeak", label: "iPeak")

The problem is, my model is mapped into Objects, not RLMObjects. Does this means the support for RealmSwift is currently broken?

@pmairoldi
Copy link
Collaborator

From what I know Charts does not use RealmSwift is because it also has to work with Objective-C as well.

@danielgindi
Copy link
Collaborator

@petester42 is right. When building the data source for Realm, we had this problem. The Realm team added a future TODO for interoperation between Realm and RealmSwift, maybe even by just accessing RealmSwift internal pointers or wrapping Realm objects. But currently these are two separate, and having duplicate code here makes this even a bigger mess.
When they'll be ready - so will we...

@danielgindi
Copy link
Collaborator

Duplicate #898

@danielgindi
Copy link
Collaborator

realm/realm-swift#4232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants