Skip to content

Instantly share code, notes, and snippets.

@swillits
Created February 23, 2017 23:34
Show Gist options
  • Save swillits/8b390b77df6196b22209855d4002f5cf to your computer and use it in GitHub Desktop.
Save swillits/8b390b77df6196b22209855d4002f5cf to your computer and use it in GitHub Desktop.
struct DataStructure {
var x: Int
var s: String
}
// Create a "convenience" namespace to separate properties and functions which we
// don't want confused with being actual properties of the original structure.
extension DataStructure {
var convenience: Convenience {
return Convenience(data: self)
}
struct Convenience {
let data: DataStructure
var description: String {
return "\(data.x) \(data.s)"
}
// ...
}
}
var ds = DataStructure(x: 5, s: "Hello")
print(ds.convenience.description)
ds.x = 9
print(ds.convenience.description)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment