As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
CustomUser was working fine.. then just stopped out of no where
B
Brad Hughes
started a topic
almost 4 years ago
my user class...
class CustomUser: User, Codable {
//open override func setValue(_ value: Any?, forUndefinedKey key: String) {}//have to put this in or i get a warning for every single variable
var first_name: String?
var last_name: String?
var number: String?
var companyName: String?
var errorNotifications: Bool?
var statusNotifications: Bool?
var errorText: Bool?
var statusText: Bool?
var machines: Array<String>?
var address: String?
@available(*, deprecated, message: "Please use Swift.Codable instead")// says use Swift.Codable but there is no sign of any code examples actually using this
override func mapping(map: Map) {
super.mapping(map: map)
first_name <- ("first_name", map["first_name"])
last_name <- ("last_name", map["last_name"])
number <- ("number", map["number"])
companyName <- ("companyName", map["companyName"])
errorNotifications <- ("errorNotifications", map["errorNotifications"])
statusNotifications <- ("statusNotifications", map["statusNotifications"])
errorText <- ("errotText", map["errorText"])
statusText <- ("statusText", map["statusText"])
machines <- ("machines", map["Machines"])
address <- ("address", map["address"])
}
}
my AppDelegate
Kinvey.sharedClient.userType = CustomUser.self
Kinvey.sharedClient.initialize(
appKey: "kid_S1_gbMQ0",
appSecret: "21893ef7a99d446a89f9f75e6c4da15d"
) {
switch $0 {
case .success(let user):
if let user = user {
print("\(user.toJSON())")
}
case .failure(let error):
print("\(error)")
}
}
User.login(username: "username", password: "password", options: nil) { (result: Result<CustomUser, Swift.Error>) in
switch result {
case .success(let user):
// The login was successful and the user is now the active user.
// The credentials saved hide the login view and show main app content.
print("usertype: \(Kinvey.sharedClient.userType)")
print("user address: \(String(describing: user.address))")// returns nill
print("user JSON: \(String(describing: user.toJSON()))")//only returns username, email, and metadata.
case .failure(let error):
// There was an error with the update save.
print("error: \(error)")
}
}
returns just the very basic information in the JSON.
this was working completely fine.. then just stopped out of no where. I didn't change any code at all.
what gives?
Best Answer
P
Pranav J
said
almost 4 years ago
Hi Brad,
Yes, please use 'Codable' instead of 'Mappable' as suggested by Nick. Also, please try typecasting your user with your custom user class to get all the attributes as follows:
let myUser = Kinvey.sharedClient.activeUser as! CustomUser
I have the same issue. For what its worth, it seems the login method inside User.swift does actually get the correct JSON back. I saw "first_name" and "last_name" returned, those are my only custom attributes. The parsing must fail after that, because the CustomUser inside the Result<> has nil for both fields.
N
Nick
said
almost 4 years ago
Brad Hughes, the solution to this issue is to update your CustomUser class to use Swift.Codable instead of the deprecated mapping method. Here is my new CustomUser class, and now the login correctly maps the custom attributes:
Yes, please use 'Codable' instead of 'Mappable' as suggested by Nick. Also, please try typecasting your user with your custom user class to get all the attributes as follows:
let myUser = Kinvey.sharedClient.activeUser as! CustomUser
Brad Hughes
my user class...
my AppDelegate
returns just the very basic information in the JSON.
this was working completely fine.. then just stopped out of no where. I didn't change any code at all.
what gives?
Hi Brad,
Yes, please use 'Codable' instead of 'Mappable' as suggested by Nick. Also, please try typecasting your user with your custom user class to get all the attributes as follows:
let myUser = Kinvey.sharedClient.activeUser as! CustomUser
Thanks,
Pranav
1 person has this question
- Oldest First
- Popular
- Newest First
Sorted by PopularNick
I have the same issue. For what its worth, it seems the login method inside User.swift does actually get the correct JSON back. I saw "first_name" and "last_name" returned, those are my only custom attributes. The parsing must fail after that, because the CustomUser inside the Result<> has nil for both fields.
Nick
Brad Hughes, the solution to this issue is to update your CustomUser class to use Swift.Codable instead of the deprecated mapping method. Here is my new CustomUser class, and now the login correctly maps the custom attributes:
Pranav J
Hi Brad,
Yes, please use 'Codable' instead of 'Mappable' as suggested by Nick. Also, please try typecasting your user with your custom user class to get all the attributes as follows:
let myUser = Kinvey.sharedClient.activeUser as! CustomUser
Thanks,
Pranav
-
Why do I get "Undefined symbols" errors when building with KinveyKit?
-
How do I register push tokens?
-
When using social login, to perform a log-out, do I need to log out of the social network, Kinvey, o
-
How can I assign additional properties to users?
-
Does KinveyKit support 64-bit ARM devices, such as iPhone 5s?
-
Authorization Token Invalid or Expired
-
BOOL and how it is stored in the database.
-
Offline saving throwing errors
-
Custom endpoint not able to form request object
-
Security through business logic
See all 437 topics