Questions tagged [didset]
in Swift this defines a property observer that executes code after a new value has been set
didset
109
questions
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") {
...
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 = "...
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 ...
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:...
-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 ...
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 ...
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 ...
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 ...
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. ...
-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("...
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: &...
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 ...
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 ...
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 ...
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
}
}