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
{{ message }}
This repository was archived by the owner on Jan 16, 2025. It is now read-only.
Hey!
Good job on Pantry!
I've built a new extension that inherits from Storable. Added extensions for default implementations (It uses Reflection to generate property-value pairs that's then typecasted to a dictionary. Now, if you want to add caching behaviour to a Struct, simply add Pantryable in an extension.
Here's a Gist
//Extensions for Pantry using reflection. Default implementation
publicprotocolPantryable:Storable{func allProperties()throws->[String:Any]func toDictionary()->[String:AnyObject]}extensionPantryable{publicfunc allProperties()throws->[String:Any]{varresult:[String:Any]=[:]letmirror=Mirror(reflecting:self)guardlet style = mirror.displayStyle where style ==.Struct || style ==.Class else{
//throw some error
throwNSError(domain:"com.kayako.kayako", code:666, userInfo:nil)}for(labelMaybe, valueMaybe)in mirror.children {guardlet label = labelMaybe else{continue}result[label]= valueMaybe
}return result
}publicfunc toDictionary()->[String:AnyObject]{do{letproperties=tryself.allProperties()varresult:[String:AnyObject]=[:]for(key,value)in properties {iflet v = value as?AnyObject{result[key]= v
}}return result
}catch{fatalError("properties can't be retrieved")}}}
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hey!
Good job on Pantry!
I've built a new extension that inherits from
Storable
. Added extensions for default implementations (It uses Reflection to generate property-value pairs that's then typecasted to a dictionary. Now, if you want to add caching behaviour to a Struct, simply addPantryable
in an extension.Here's a Gist
The text was updated successfully, but these errors were encountered: