Start a new topic
Answered

down casting user to customUser after user query to obtain an attribute

I am trying to look up a use through the user query method and then downcast the user to CustomUser to be able to retrieve the profilePicId in  CustomUser collection but it does not seem to work.Below is my code



func getHostProfilePicId(username : String){

   if let user = Kinvey.sharedClient.activeUser{

     let userQuery = UserQuery{

       $0.username = email

     }

       user.lookup(userQuery) {

          if let users = users {

             let foundUser = users[0] as? CustomUser  

             print(foundUser?,profilePicId)

          }

       }

   }


}


From the code above I proceed to print (foundUser?.profilePicId) but I get nil.Same with foundUser.I do get a user at array index 0 but the downcast is not working.How do i go about this?

 

    }

 


Best Answer

Hello Bkwart,


We are pleased to inform you that a new release of the iOS SDK v3.5.0 has been posted and is available for download at the following location.


http://devcenter.kinvey.com/ios/downloads


This update fixes the problem described in this ticket regarding downcasting problem.


At your convenience, please download and test the fix and let us know if it works to your satisfaction.


Regards,


Billy Gee


Answer

Hello Bkwart,


We are pleased to inform you that a new release of the iOS SDK v3.5.0 has been posted and is available for download at the following location.


http://devcenter.kinvey.com/ios/downloads


This update fixes the problem described in this ticket regarding downcasting problem.


At your convenience, please download and test the fix and let us know if it works to your satisfaction.


Regards,


Billy Gee

Bkwart,


This has been escalated to engineering. I will update you once I have more information from engineering.


Thanks,

Pranav

Kinvey

MLIBZ-1770

Bkwart,


Check spelling of "profilePicId" in your mapping function. I assume this might be because of the spellchecker. You have written "profilePidId".


Thanks,

Pranav

Kinvey

1. I am storing it as a string

2 class CustomUser: User{

   var profilePicId : String?

   var firstName : String?

   var lastName : String?


    override fun mapping(map : Map){

        super.mapping(map: map)

        profilePidId <- map["profilePidId"]

        firstName <- map["firstName"]

        lastName <- map["lastName"]

    } 

}

 3. SDK v3.3.8,

Bkwart,

  1. How are you storing "profilePicId" in user collection? Is it a string or int?
  2. Can you share custom user class definition? Just want to check how you have added/mapped "profilePicId" in class definition?
  3. What version of the Kinvey SDK you are using?


Thanks,

Pranav

Kinvey

 

Login or Signup to post a comment