Backendless Support
 
Solved

Issue when registering user and getting Object ID

When we register a user like this everything works fine.

  1. backendless?.userService.register(user, response: { (registeredUser) in
  2. print ("the user is reg")
  3. let userObjectId = registeredUser?.value(forKey: "objectId") as! String
  4. }, error: { (fault) in
  5. print("The fault is \(String(describing: fault))")
  6. })

But when we do this instead to get the object ID, it crashes.

  1. let userObjectId = registeredUser?.objectId as String

We aren't having this issue anymore but I am sure others will use the second method because it is an available option.

Leave a Comment

Comments (11)

photo
1

Hi Nevin,

Did you see that second method somewhere in the docs?

photo
1

No but it is available in Xcode

photo
1

Can you please check what type is registeredUser variable of?

photo
1

it is of type BackendlessUser

  1. let registeredUser: (BackendlessUser?)

Is the first method the correct way of doing it?

photo
1

I see that objectId field in BackendlessUser class is of type NSString. Is it possible that NSStrings cannot be cast to Swift's Strings via 'as String' construction?

photo
1

Yes, I saw that also and I thought NSString was gone in swift 3 but this was working previously with backendless 3.0 (using swift 3).

Take a look at this.

https://stackoverflow.com/questions/24038629/swift-which-types-to-use-nsstring-or-string

photo
1

Which version of the SDK are you using? I can't find the `register` method in the 4.0 version: https://github.com/Backendless/ios-SDK/blob/4.0/SDK/ios/backendless/include/UserService.h

photo
1

we are using 4.0 (version 13). it is in your docs. 2a9f36cb41e577dbb38fb6736161308d

photo
photo
1

I have created an internal task (ID BKNDLSS-15165) to investigate this behaviour. We shall notify you here as soon as we have any news.

photo
1

Hello, Nevin

This issue has been fixed in iOS SDK v4.0b14.

Regards, Olga

photo
1

Perfect. Thanks. What is the best way to get the ObjectID? What is best practice in this scenario?