Skip to content

Instantly share code, notes, and snippets.

@KaQuMiQ
Created March 17, 2020 12:15
Show Gist options
  • Select an option

  • Save KaQuMiQ/db9c651690d9a51e749c5fc96fe71b2f to your computer and use it in GitHub Desktop.

Select an option

Save KaQuMiQ/db9c651690d9a51e749c5fc96fe71b2f to your computer and use it in GitHub Desktop.
Set only property example
struct SomeType {
private var store: Any = 0 // or something else to proxy properties
var value: Any {
@available(*, unavailable)
get { fatalError("unavailable") }
set { store = newValue}
}
}
@KaQuMiQ
Copy link
Author

KaQuMiQ commented Mar 17, 2020

Example

var some = SomeType()
some.value = "WORKS"
_ = some.value // compile error - Getter for 'value' is unavailable

Might be useful in proxy for types where getting is hard or not available while avoiding func setValue(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment