Last active
March 10, 2016 10:37
-
-
Save libdx/aa04bb51e5296577d7e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Attributed { | |
var attrs: Attrs { get } | |
} | |
struct Attrs { | |
let name: String | |
let sortBy: String | |
let keyPath: [String] | |
// init has defaults | |
init(name: String, sortBy: String, keyPath: [String] = []) { | |
self.name = name | |
self.sortBy = sortBy | |
self.keyPath = keyPath | |
} | |
} | |
struct SomeAttributed: Attributed { | |
let attrs = Attrs( | |
name: "some", | |
sortBy: "priority", | |
keyPath: ["my", "some"] | |
) | |
} | |
struct OtherAttributed: Attributed { | |
// new attributes can be added with defaul value, therefore no need to update all attributed declarations | |
let attrs = Attrs( | |
name: "other", | |
sortBy: "id" | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment