Post not yet marked as solved
Post marked as unsolved with 3 replies, 259 views
Sorry, maybe the title seemed hard to understand.
Here is the situation:
A structure with google API URL properties, which are wrapped together and will be stored as Data in userDefaults.
struct googleApiLibrary: Codable {
let authUrl: URL
let tokenUrl: URL
let userinfoUrl: URL
}
A function with a parameter, Its job is to retrieve the googleApiLibrary from UserDefault, decode back to structure and get the corresponding URL based on the parameter key provided.
func loadGmailApiUrl(forKey key: String) -> URL {
		guard let encodedValue = defaults.object(forKey: "gmailApiLibrary") as? Data,
let decodedValue = try? JSONDecoder().decode(GmailApiLibrary.self, from: encodedValue) else { return }
return decodedValue.<???>
}
The problem that has bothered me for a long time is, how can I use the String parameter key, to access the structure's property (the appropriate URL to the key).