Skip to content

Instantly share code, notes, and snippets.

@libdx
Last active March 10, 2016 10:37
Show Gist options
  • Save libdx/aa04bb51e5296577d7e8 to your computer and use it in GitHub Desktop.
Save libdx/aa04bb51e5296577d7e8 to your computer and use it in GitHub Desktop.
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