Skip to main content
How are we doing? Please help us improve Stack Overflow. Take our short survey

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-wrapper
-1 votes
1 answer
92 views

How to force non-optional type (for array element) on compile time in Swift? [closed]

struct MyStruct { @ArrayOfNonOptionalElements var arr: [SomeNonOptionalType] } where @ArrayOfNonOptionalElements is a propertyWrapper. So, how to force non-optionality for the type inside? Is it ...
Roman's user avatar
  • 1,485
0 votes
0 answers
32 views

Apple's own Invalidating property wrapper example doesn't compile

In iOS 15, Apple introduced the @Invalidating property wrapper. The documentation shows an example: class MyView: UIView { @Invalidating(.display) var badgeColor: UIColor @Invalidating(....
matt's user avatar
  • 528k
0 votes
3 answers
100 views

What is the difference between (@StateObject & @StateObject) and (@StateObject & @ObservedObject) in Parent and Child Views

@StateObject & @StateObject in Both Parent and ChildView import SwiftUI class Counter: ObservableObject { @Published var count: Int = 0 func increment() { count += 1 } } ...
S SANTOSH's user avatar
-2 votes
1 answer
78 views

Binding with a ternary between parent/child views in SwiftUI [closed]

Consider this code in which I'm trying to continuously animate a set of circles from red to blue: struct ContentView: View { let timer = Timer.publish(every: 1.0, on: .main, in: .common)....
soleil's user avatar
  • 12.8k
2 votes
2 answers
161 views

Swift Property Wrapper on Struct

I am struggling to create a swift struct, where I can use a property wrapper to decode some JSON that sometimes requires a value to conform to a specific type, but other times may become a dictionary ...
Euan Traynor's user avatar
1 vote
0 answers
65 views

SwiftUI Alert setting presentation condition true in it's button action closure not showing the alert again

So the thing I want to do is that I have an api call if it fails I show an alert with message, OK button and Retry Button. Everything is working good but when I do retry it don't shows the alert again ...
user3745635's user avatar
4 votes
1 answer
879 views

Can't use Property Wrappers on a class marked with @Observable

I have a class which is similar to: final class Person { @Resettable var name = "John Doe" func revertName() { name = $name } } @propertyWrapper struct Resettable&...
rayaantaneja's user avatar
  • 1,672
0 votes
1 answer
213 views

Swift: Union Type in Property Wrapper

In Swift, you can specify a union type using an enum. For example: enum IntOrString { case int(Int) case string(String) } Now I want to write a property wrapper, which I can apply to ...
tierriminator's user avatar
0 votes
1 answer
110 views

SwiftUI - immutable @State variable when change it "from outside" via UIHostController

Situation During migration of some UIKit view classes to SwiftUI, I have faced next case: I have a simple view class, responsible for data fetching and displaying. Its structure is pretty simple and ...
Viktor's user avatar
  • 1,107
-1 votes
1 answer
100 views

How to have @State that is an array with the size that depends on a FetchRequest

I have an app that is outlined in the following. Most of the code I have adapted from https://www.hackingwithswift.com/books/ios-swiftui/how-to-combine-core-data-and-swiftui But the part I have ...
Dogahe's user avatar
  • 1,400
1 vote
2 answers
185 views

Are Swift Property Wrappers attributes?

Using a propertyWrapperseems to have the same syntax as attribute. For instance, compare this custom propertyWrapper: @propertyWrapper struct Capitalize { private var value: String = "" ...
Joakim Sjöstedt's user avatar
0 votes
0 answers
17 views

Initialise Property Wrapper in the init [duplicate]

I have the following simple property wrapper @propertyWrapper struct TestWrapper<Value> { private var value: Value init(wrappedValue: @autoclosure @escaping () -> Value) { ...
Ruben's user avatar
  • 290
1 vote
1 answer
209 views

Custom property wrapper in a SwiftUI viewmodel

I've been working on a SwiftUI wrapper around a MKMapView, and in trying to work on a binding value for the visible area of the map, I created a custom property wrapper that allows the ...
RL2000's user avatar
  • 987
0 votes
1 answer
119 views

A property wrapper causes JSONDecoder to fail when property is not in the json string

I have a data model class with custom rules to deserialize from json. Specifically, the property flexibleProp can be defined in JSON as either String? or Int?. On my model class it should always be ...
Mando's user avatar
  • 11.7k
1 vote
3 answers
182 views

Adding additional attribute to @State property

I have a SwiftUI view that takes user name in a String declared as a State property. How can I add an additional attribute to the same variable? struct Login: View { @Trimmed(characterSet: ....
Kaunteya's user avatar
  • 3,092

15 30 50 per page
1
2 3 4 5
9