iOS SDK cast problem

I was following https://backendless.com/documentation/data/ios/data_search_and_query.htm

But the list I retrieved with the query cannot be casted into the type.

    let dataStore = backendless.data.of(Found.ofClass())

    let result = dataStore.findFirstFault(&error)

    let found = result as! Found // This failes

    if error == nil {

        print("Result: \(result)")

        print("Found: \(found.objectId)")

    }

    else {

        print("Server reported an error: \(error)")

    }

Can you check the “error” object before you get to result?

let backendless = Backendless.sharedInstance()

    let dataStore = backendless.data.of(Found.ofClass())

    let result = dataStore.findFirstFault(&error)

    if error == nil {

        print("Result: \(result)")

    }

    else {

        print("Server reported an error: \(error)")

    }

    let found = result as! Found // This failes

    print(found.objectId)

Output:

Result: {
“___class” = Found;
“__meta” = “{“relationRemovalIds”:{},“selectedProperties”:[“imgUrl”,”__updated__meta",“postUrl”,“gender”,“created”,"___class",“ownerId”,“updated”,“objectId”,“foundLocationStr”],“relatedObjects”:{}}";
created = “2015-06-13 07:46:52 +0000”;
foundLocationStr = “Regional Animal Services of King County”;
gender = Male;
imgUrl = “http://www.petharbor.com/get_image.asp?RES=detail&ID=A466695&LOCATION=KING”;
objectId = 7yotLsONuO;
ownerId = “<null>”;
postUrl = “http://www.petharbor.com/pet.asp?uaid=KING.A466695”;
updated = “2015-06-13 07:46:52 +0000”;
}

Could not cast value of type ‘__NSDictionaryM’ (0x10764fd38) to ‘SeattleFoundDogs.Found’ (0x103df3740).

If the “Found” class defined in a separate .swift file?

Yes. There is a Found.swift file.

It is resolved properly. It is used successfully in the line
let dataStore = backendless.data.of(Found.ofClass())

Hi Gordon,

Give me your appId and secretKey, I will investigate this issue with your data.
My email: slavav@themidnightcoders.com

Regards,
Slava

Gordon, could you also show what your Found class looks like?

import Foundation

class Found : NSObject {
var objectId: String?
var postUrl: String?
var imgUrl: String?
var foundLocationStr: String?
var gender: String?
var created: NSDate?
var updated: NSDate?

}

Hi, Vyacheslav Vdovichenko
Thanks but no.

Gordon, Vyacheslav is our employee, if not him, very few other people would be able to help.

Hi Mark,

I could not tell that he’s an employee from the email address.
I will just email him my code. Including app id and secret.

We already have your code. We need app ID and secret key.you can send it to support@backendless.com

Sent. Thank you!

here’s what I did:

    got the code you posted in this topic and put into a blank, brand-new project put your app id and secret key ran the app.
Worked exactly as expected - no errors whatsoever: http://support.backendless.com/public/attachments/973cf4ee39cc55f3dc14207da523dee8.png</img>

http://support.backendless.com/public/attachments/aa52ed383a18961e7d3fae746b7d3e02.png&lt;/img&gt;

This confirms that API is working properly and the error you experience is caused by something else. You can try creating a new project and isolate the use-case to that method and see if it works

That is good news. I’m still trying.
http://support.backendless.com/public/attachments/1a98bc6835a781c82fd3ca62a395eff5.png&lt;/img&gt;

Now I typed the code exactly like yours. Still fails.
http://support.backendless.com/public/attachments/f1924aa259c108f467577b8cde27577b.png&lt;/img&gt;

I created a new project and it seems works.http://support.backendless.com/public/attachments/9fe0d6fa50f013771939631084fbd6f5.png&lt;/img&gt;

I found the problem.
In the Info.plist file. I have Bundle Identifier and Bundle Name as plan strings. If I change them to
$(PRODUCT_NAME) and $(PRODUCT_BUNDLE_IDENTIFIER) , then I can cast!
Why is that?

http://support.backendless.com/public/attachments/f71a0aa58eef41d742bc6a3f34164fc5.jpg&lt;/img&gt;
http://support.backendless.com/public/attachments/13283f19a6144296ba41ba7c9a2d900e.jpg&lt;/img&gt;

We used “Bundle name” to determine full type name for the classes used in the app. This is no longer required. The latest lib in github contains a change that removes the requirement for having Bundle name as $(PRODUCT_NAME)

Cool!