Skip to main content

Questions tagged [didset]

in Swift this defines a property observer that executes code after a new value has been set

didset
1 vote
1 answer
95 views

SwiftUI @Binding how to confirm the source is updating [duplicate]

Here's an example that demonstrates what I'm seeing: struct Tapper: View { @Binding var incrementMe: Int var body: some View { Button("Button With Binding") { ...
Murray Sagal's user avatar
  • 8,604
0 votes
1 answer
59 views

Need some knowledge on Struct and specially property wrapper

struct XA { static var xa = "Advanced" var xb: String { didSet { XA.xa = oldValue } }} var objXA = XA(xb: "Turing") print(XA.xa) // Advanced objXA.xb = "...
sandeep tomar's user avatar
0 votes
1 answer
107 views

Swift can lazy, get and didSet together

Can we do get and didSet together with lazy keyword. I have an array it fetch data from database (get) and another thing when that array will modify i will call delegate to reload data in didSet. Its ...
Yogesh Patel's user avatar
  • 1,997
1 vote
2 answers
189 views

Stop firing didSet to avoid infinite recursion with didSet in Swift with multiple properties

I have a class with two properties whose value is set using didSet. class MyClass { var myProp1: Bool { didSet { self.myProp2 += blinks ? 1 : -1 } } var myProp2:...
ArturJD96's user avatar
-1 votes
3 answers
831 views

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 ...
Scott Wood's user avatar
2 votes
1 answer
937 views

SwiftUI onReceive is it possible to get oldValue?

I have a custom TabView and I want to Bind to a State to change tabs. I also want to detect if the user has tapped the same tab again in order to scroll to the top of that view. didSet isn't called ...
Dan's user avatar
  • 623
0 votes
1 answer
29 views

Stuck at reassigning TableView Cell property

I'm working on an App where you can track your reading progress for Books. The HomeViewController contains a TableView that lists the books you have added. It has a progress Bar and shows what page ...
alias.marv's user avatar
0 votes
2 answers
734 views

Blinking symbol with didSet in SwiftUI

This is synthesized from a much larger app. I'm trying to blink an SF symbol in SwiftUI by activating a timer in a property's didSet. A print statement inside timer prints the expected value but the ...
Phantom59's user avatar
  • 1,039
2 votes
1 answer
541 views

SwiftUI: didSet doesn't update view

In the following, reproduced example, I have the following code which makes up a single screen. There's a lot of code, but it's simple! The intended function: The screen is filled with a plain color. ...
chuk's user avatar
  • 79
-1 votes
1 answer
87 views

swift property observer for data processing

How can I get notified when data has changed to process it? I have a simple code for easy to understand what I want: class Data { var data: [Int] = [] { didSet { print("...
Anton's user avatar
  • 339
0 votes
1 answer
181 views

How to save a Stepper data to UserDefaults in SwiftUI?

struct Test { @State private var steps = UserDefaults.standard.integer(forKey: "steps") { didSet { steps = UserDefaults.standard.integer(forKey: &...
Aashish's user avatar
  • 2,662
3 votes
2 answers
2k views

SwiftUI: Action not triggering with toggle

I'm trying to trigger an action with a toggle switch. In this case the print message "value did change" doesn't show up on console after clicking on the toggle. This is targeted for a macOS ...
Eric's user avatar
  • 764
0 votes
0 answers
56 views

Swift: array is set but is then empty when accessed

I have an array which is set once a specific API is called. However when I then try to access this array at a later point it is empty again. The class in question looks like this: class ...
DevB1's user avatar
  • 1,435
0 votes
2 answers
821 views

What is the proper way to update my label's text from a function?

I am trying to have my UILabel's text automatically update in increments of 1 based on a looping Timer. The label is linked to a variable. I'm not sure if it matters but I am doing my UI ...
pawCheese's user avatar
1 vote
1 answer
266 views

swift - didSet not called on UIImageView

How can I get didSet to recognize when imageView.image has been set? It only seems to be called during initialization. @IBOutlet weak var imageView: UIImageView! { didSet { //do stuff } }
squarehippo10's user avatar

15 30 50 per page
1
2 3 4 5
8