You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for your answer, but object type it's not known.
Since objects are of codable type, I have performed the serialization of the object into Dictionary and from this I have retrieved the value through Keypath.
`
public func valueForKeyPath(keyPath: String) -> T? {
var keys = keyPath.components(separatedBy: ".")
guard let first = keys.first as? Key else { print("Unable to use string as key on type: (Key.self)"); return nil }
guard let value = self[first] else { return nil }
keys.remove(at: 0)
if !keys.isEmpty, let subDict = value as? [NSObject:AnyObject] {
let rejoined = keys.joined(separator: ".")
return subDict.valueForKeyPath(keyPath: rejoined)
}
return value as? T
}
`
I think this is not the best approach for performance!
I have a complex classes of this type
`public class Info: Codable {
}
public struct UserModel: Codable {
public var username: String?
public var name: String?
}`
I want to access sub properties in this way "user.info", is it possibile?
var obj = Info() let xxx: String? = try? get("user.info", from: obj)
The text was updated successfully, but these errors were encountered: