My ios app is still referencing ‘Backendless’ in the pod file and not ‘BackendlessSwift’
I tried switching and pod update but got a lot of errors like couldn’t find bridging-header file etc etc when I rebuilt project. Is it ok to use just Backendless or do I need to change to BackendlessSwift in the pod file and work through all the errors?
Mike
Hello,
pod 'Backendless'
references to our old library which is not supported anymore.
If you want to use our newest Swift-SDK please change it to pod 'BackendlessSwift'
.
Our newest SDK is different from the oldest one - thats why errors occur (and that’s an expected behaviour).
Regards,
Olha
Thanks Olha
I was using
Types.tryblock({ () -> Void in
(like for logging out etc)
with the old ‘backendless’ pod reference - it now complains use of unresolved identifier Types with the new ‘backendlessswift’ ref - do I need to translate this kind of code to the new responseHandler, errorHandler kind of syntax if you understand or can I use the old style tryblock somehow (just for speed until I have more time!)
Yes, you should translate this kind of code to the new responseHandler, errorHandler kind, try-catches and Types are no longer available.
OK thats another chunk of my life gone
Hi Olha
Finally got around to translating some old style code. I wondered if you had a more complete example of using the new responseHandler etc than I can find in the docs. Here is some old code (abbreviated) and attempt at new code, but I run into problems. I got the gist of it, but confused on a few bits, like returning the results from the async backendless call correctly. Any help would be much appreciated.
old style code:
func getLoyaltyPoints(_ id: String) -> Int16{
let dataQuery = DataQueryBuilder()
dataQuery?.setWhereClause(whereClause)
dataQuery?.setPageSize(100)
let dataStore = backendless?.data.of(LoyaltyPoints().ofClass())
var response = [LoyaltyPoints]()
Types.tryblock({ () -> Void in
response = dataStore?.find(dataQuery) as! [LoyaltyPoints]
self.loyaltyPointValue = 0
while (response.count != 0){
for loyaltyRecord in response {
//logic to add up points
numberPoints = numberPoints + loyaltyRecord.loyaltyPointValue
}
dataQuery?.prepareNextPage(). //there could be more than 100 records
response = dataStore?.find(dataQuery) as! [LoyaltyPoints]
}
},
catchblock: { (exception) -> Void in
})
return numberPoints
so trying to write equivalent in new style syntax I have this:
func getLoyaltyPointsV2(_ id: String) -> Int16{
let dataQuery = DataQueryBuilder()
dataQuery?.setWhereClause(whereClause)
dataQuery?.setPageSize(100)
let dataStore = backendless?.data.of(LoyaltyPoints().ofClass())
dataStore!.find(dataQuery, response: { foundPoints in
for genericRecord in foundPoints! {
//logic to add up points
let loyaltyRecord = genericRecord as! LoyaltyPoints //casting to loyaltyRecord class but there must be a neater way to do this earlier rather than here?
numberPoints = numberPoints + loyaltyRecord.loyaltyPointValue
//this needs to get returned to main function **HERE**
}
}, error: { fault in
print("Error: \(fault?.message ?? "")")
})
return numberPoints //how do I return this value? I need to get it from the handler somehow (**SEE HERE**). Obviously at the moment this just gets returned immediately before the handler is completed.
}
Hello,
Swift-SDK provides only async methods. You should manage the return logic on your own.
E.g. you can use PromiseKit or dispatch groups or semaphores etc.
Regards,
Olha
Hi Olha
I thought you might say that, just wondered if you had a complete code example in your docs for completeness - just to save a bit of time? No probs if not.
Mike
Oh no sorry, we provide only async examples.
Regards,
Olha