swift relationships and broken object graph

I have an app written in swift which is using simple table access (no custom business logic). This app was migrated from parse.com and the tables use several relationships. When querying for some objects things work fine, but in some cases the object graph returned from a findById is broken. This happens when there’s a circular dependency. This looks to be an iOS SDK issue because the AMF returned (when viewed in Charles proxy) looks fine.

Specifically, I have a Competitor who has a relationship to all their Games and the Game has relationships to playerOne and playerTwo (both of type Competitor). When I find a Competitor by Id the other nested Competitor exists in the response graph fine, but not the requested competitor (the graph root). Screenshot of the object graph attached which shows that playerOne is a different instance and only partially populated.

See below the server models file which shows swift class definitions.

Tracing the code in the debugger, multiple instances of each class are created, but some are instantiated more than I expect based on the payload downloaded.


import Foundation


func registerServerModels() {
    let p = Backendless.sharedInstance().persistenceService
    
    p.mapTableToClass("League", type: BLeague.self)
    p.mapTableToClass("Competitor", type: BCompetitor.self)
    p.mapTableToClass("Game", type: BGame.self)
}


class BLeague : NSObject {
    
    var objectId: String?
    var created: NSDate?
    var updated: NSDate?
    var competitors: [ BCompetitor ] = []
    var leagueName: String?
    var startDate: String?
    var type: String?
}


class BCompetitor : NSObject {
    
    var objectId: String?
    var created: NSDate?
    var updated: NSDate?
    var user: BackendlessUser?
    var games: [ BGame ] = []
    var score: Int?
    var completedGameCount: Int?
}


class BGame : NSObject {
    
    var created: NSDate?
    var updated: NSDate?
    var playerOne: BCompetitor?
    var playerTwo: BCompetitor?
    var winner: BCompetitor?
    var type: String?
    var proposedDate: NSDate?
    var proposedByPlayer: Int?
    var dateAccepted: Bool?
    var complete: Bool?
}

Hi Wain,

thanks for reporting your issue, I have assigned an internal ticket to our dev for investigating this problem.
Soon he will contact with you to help.

Assigned tag - BKNDLSS-12278

Regards,
Stanislav

I have a similar issue, so I am posting this just to get an update when this issue is fixed.

Regards,

George

Hi,

I see a new version of the SDK has been released on github (Backendless-ios-SDK 3.0.14), but the release notes leave a lot to be desired (lib was rebuilt isn’t very revealing).

Does this release cover a fix for this issue?

I’ll install it and give it a try but the change tracking could be improved :wink:

Thanks

Hi Wain,

I see that the original ticket is still open, so it seems that this issue hasn’t been fixed yet.

We’ve fixed this issue, you could update latest Backendless SDK from CocoaPods (3.0.15 release) or from github (CommLibiOS & backendless).

I had the same issue, involving circular dependencies, and I downloaded the new release using pods. The issue is partially solved, since the problem re-appears when the circular dependency is in the User table and stay logged in is enabled. Having stay logged in enabled tries to fetch the User object and goes into an infinite loop.

I had opened a thread for this issue right here

http://support.backendless.com/t/could-not-load-any-objective-c-class-information

but since this is the same issue after communication with Mark I am following this thread.
Please have a look at this use case.

Regards,

George

Please provide a sample project, which demonsrated the issue.

This looks to have resolved my issue, from a brief test just now. I don’t have any relationships from the user object however (so no circularity) so I can’t comment on that part (below).

Hi again, you can use this class as a property in the User’s table

class UserLocation:NSObject{

var isPrivate:Bool=false

var location:GeoPoint?

var user:BackendlessUser?

}
Having this creates a circular dependency between UserLocation and User. When stay logged in is enabled and autoload enabled, making this call crashes the app when user is running the app the second time.
backendless.initApp(APP_ID, secret: SECRET_KEY, version: VERSION_NUM)

backendless.userService.setStayLoggedIn(true)

let userLoggedIn = backendless.userService.isValidUserToken()

if(!userLoggednIn.boolValue){
backendless.userService.login("some_user@test.com", password: “test”, response: { (user:BackendlessUser!) in

}) { (fault:Fault!) in

}
}

Regards,

George

The issue with “circular dependency in the User table and stay logged in is enabled” is fixed.

You should update the latest Backendless SDK with CocoaPods (3.0.16 release) or from github (CommLibiOS & backendless).

Thank you very much I will update my project.

Regards,

George