Skip to content

Instantly share code, notes, and snippets.

@RoyalIcing
Created July 26, 2015 08:17
Show Gist options
  • Save RoyalIcing/2f8a2d333f5c2f59e4dc to your computer and use it in GitHub Desktop.
Save RoyalIcing/2f8a2d333f5c2f59e4dc to your computer and use it in GitHub Desktop.
Parse & JSON API
protocol ValueStorable {
subscript(key: String) -> AnyObject? { get set }
}
internal protocol ValueStorableUpdater {
init?(fromStorable storable: ValueStorable)
func updateStorable(inout storable: ValueStorable)
}
extension PFObject {
private struct ParseStorable: ValueStorable {
let parseObject: PFObject
subscript(key: String) -> AnyObject? {
get {
return parseObject[key]
}
set {
parseObject[key] = newValue
}
}
}
final var storable: ValueStorable {
return ParseStorable(parseObject: self)
}
}
struct RecordJSON: ValueStorable {
typealias Dictionary = [String: AnyObject]
var dictionary: Dictionary
subscript(key: String) -> AnyObject? {
get {
return dictionary[key]
}
set {
dictionary[key] = newValue
}
}
}
extension RecordJSON {
init() {
self.init(dictionary: Dictionary())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment