Questions tagged [property-wrapper]

Property Wrappers are a feature of Swift 5.1 and beyond. Should be tagged onto questions using `@` to mark a Property Wrapper. Should not be used for `@` referring to Objective-C interoperability (e.g. @IBAction).

Property Wrappers are a feature of Swift 5.1 and beyond. Should be tagged onto questions using @ to mark a Property Wrapper. Should not be used for @ referring to Objective-C interoperability (e.g. @IBAction).

Property wrappers can be defined by using struct, class, or enum. It can also used when declaring properties within those types.

Uses:

  • Constraining Values
  • Transforming Values on Property Assignment
  • Changing Synthesized Equality and Comparison Semantics
  • Auditing Property Access

References


Related tags

123 questions
0
votes
1 answer

How to detect Type is Optional for Generic propertyWrapper

I'm creating a property wrapper for UserDefaults. What i'm trying to achieve is: Setting a non-nil value to property will store it in User default. Setting nil will remove the Object from UserDefault. But below code throws compiler…
Lal Krishna
  • 15,485
  • 6
  • 64
  • 84
-1
votes
3 answers

Why does setting property in didSet of published property cause infinite loop?

I'm attempting to use SwiftUI Toggle to control the state of a boolean stored on the server. On the didSet of the @Published property, I'm making a network call to persist the state. Successful network calls work great. On failure, I am attempting…
-3
votes
1 answer

Where to use @StateObject and ObservableObject?

I'm learning swiftUI and I'm getting confused in @StateObject and @ObservableObject when to use them and where to use them.
1 2 3
8
9