Created
February 23, 2017 23:34
-
-
Save swillits/8b390b77df6196b22209855d4002f5cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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