- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 153
 
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
struct User3: Codable, Defaults.Serializable {
    let name: String
    let age: String
}
extension Defaults.Keys {
    static let user3 = Key<User3>("user3", default: .init(name: "Hello", age: "24"))
}
...
    func test2() {
        print(Defaults[.user3])
        print(Defaults[.user3])
    }
...The above code will call bridge.deserialize twice. If user3 is an array and there are many attributes of the User3 type, will it affect performance?
Would it be better to cache the data after Defaults[.user3] is executed once?
extension Defaults.Serializable {
	....
	static func toValue(_ anyObject: Any) -> Self? {
		// Return directly if `anyObject` can cast to Value, since it means `Value` is a natively supported type.
		if
			isNativelySupportedType,
			let anyObject = anyObject as? Self
		{
			return anyObject
		} else if let value = bridge.deserialize(anyObject as? Serializable) {
			return value as? Self
		}
		return nil
	}
        ....
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed