Swift object saving causes !!! BLOCED !!!

I am currently trying to set up our iOS app with the backendless service. Our app is written in Swift and uses the provided Objective-C Header Bridging. Although the compatability with Swift is there, it is very hard to get anywhere with the SDK so far, because there isn’t any documentation on the Swift-enabled functionality.

That being said, I set up a documentation-inspired Swift example of object-saving and get a weird error code:
“AnonymousObject -> setFieldsDirect: (!!! BLOCKED !!!) PROPERTY ‘cause’[<NamedObject: 0x78ec9910>]”

My synctest-class in Swift is the following:


class BLSync: Responder {
    
    func syncObjects() {
    
        let managedObjectContext:NSManagedObjectContext = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext!
        
        let request : NSFetchRequest = NSFetchRequest(entityName: "Toilet")
        let result = managedObjectContext.executeFetchRequest(request, error: nil) as [Toilet]
    
        if !result.isEmpty {
            let toilet = result.first
            
            let blToilet = BLToilet(toilet: toilet!)
            
            let responder = Responder(responder: self, selResponseHandler:Selector("responseHandler"), selErrorHandler:Selector("errorHandler"))
            let dataStore = PersistenceService()
            dataStore.of(BLToilet.classForCoder())
            dataStore.save(blToilet, responder: responder)
            
            println("Saved object in Backendless")
            
        } else {
            println("Didn't save object in Backendless")
        }
        
    }
    
    override func responseHandler(response: AnyObject) -> AnyObject! {
        println("\(response)")
        return response
    }
    
    override func errorHandler(fault: Fault!) {
        println(fault.debugDescription)
        println(fault.detail)
        println(fault.description)
        println(fault.message)
    }
    
}

The syncObjects function gets an object from the CoreData context, converts it into a Backendless compatible NSObject and then attempts to safe that object.

What could be wrong with this attempt and would it be possible, that you update your documentation for the Swift language?

Thanks!
Daniel Steiert

Hi, Daniel.

This

“The syncObjects function gets an object from the CoreData context, converts it into a Backendless compatible NSObject and then attempts to safe that object.”

works? Or your code does not work at all?

Regards,
Kate.

Are you serious? I opened up this issue with the headline showing you it doesn’t work.

Yes, I’m serious. This error should not stop work of application logic and may appear in different cases. I just wanted to clarify your issue.
We will check this problem and will notify you.

Regards,
Kate.

Hi Daniel,

You have got a log:
“AnonymousObject -> setFieldsDirect: (!!! BLOCKED !!!) PROPERTY ‘cause’[<NamedObject: 0x78ec9910>]”
because your invocation returned the Fault instance as response.

Here is the example of persistence service usage:

class Weather : BackendlessEntity {

var temperature = 24.7
var condition = “Very Nice”

// description func
func description() -> NSString {
return "<Weather> " + condition + “:” + temperature.description
}
}

// create Backendless instance

var backendless = Backendless.sharedInstance();

// - sync method with class instance/fault as return
var result : AnyObject = backendless.persistenceService.save(Weather())
if (result is Weather) {

var obj : AnyObject = backendless.persistenceService.findById(“Weather”, sid:(result as Weather).objectId)
}
if (result is Fault) {
var fault : Fault = result as Fault
NSLog(“FAULT”)
}

// - sync method with fault as reference
var fault : Fault?
var weather : Weather = backendless.persistenceService.save(Weather(), error: &fault) as Weather
if (fault == nil) {

var obj : AnyObject = backendless.persistenceService.findById(“Weather”, sid: weather.objectId)
}
else {
NSLog(“FAULT”)
}

// - async method with block-based callbacks
backendless.persistenceService.save(

Weather(),
response: { (var result : AnyObject!) -> () in
var obj : AnyObject = self.backendless.persistenceService.findById(“Weather”, sid: (result as Weather).objectId)
},
error: { (var fault : Fault!) -> () in
NSLog(“FAULT”)
}
)

// - save object as dictionary of properties
var os = ["iOS":"Apple", "android":"Google"]
var fault : Fault?
var result = backendless.persistenceService.save("MobileOS", entity:os, error: &fault)

As you can see, all saving object properties MUST be “var”.

Give me your swift project for investigation if you will have a some problem.