Skip to content

Instantly share code, notes, and snippets.

@mamnun
Created March 9, 2017 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamnun/9aab28db245cf4b9dd568fe01021f716 to your computer and use it in GitHub Desktop.
Save mamnun/9aab28db245cf4b9dd568fe01021f716 to your computer and use it in GitHub Desktop.
Reference types in swift structs
struct AdConfig {
var prefetchCount:Int
var wrapperView:UIView?
static let `default`: AdConfig = AdConfig(prefetchCount: 10, wrapperView: UIView(frame:CGRect.zero))
}
print(AdConfig.default.wrapperView?.backgroundColor) // prints nil
var customConfig = AdConfig.default
customConfig.wrapperView?.backgroundColor = UIColor.red
print(AdConfig.default.wrapperView?.backgroundColor) // prints red
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment