Questions tagged [property-observer]

52 questions
0
votes
0 answers

How does this code change a button's background color when clicked?

The following code gotten from this post supposedly changes a button's color when it is pressed. override var highlighted: Bool { didSet { if highlighted { backgroundColor = UIColor.lightGrayColor() …
Foobar
  • 7,458
  • 16
  • 81
  • 161
0
votes
1 answer

How to set a property observer on system variable

I have the following variable: private var screenWidth = UIScreen.mainScreen().bounds.width I was wondering how I could set a property observer on it? Or get the latest version of it when it updates?
Foobar
  • 7,458
  • 16
  • 81
  • 161
0
votes
1 answer

Property observer working for bounds but not frame

I'm working on this project and I have one scene on the Storyboard. The scene is a TableViewController. The table view have a custom prototype cell (linked to CustomCell.swift). Inside the prototype cell there's a label and a custom UIView (linked…
CrazyJony
  • 925
  • 1
  • 9
  • 12
0
votes
1 answer

Why property observers can be added to stored properties, but not lazy stored properties

I'm new to Swift and is trying to learn the concept of Property observer. In one of the Youtube tutorials, someone mentioned that "property observers can be added to stored properties, but not lazy stored properties".
Thor
  • 9,638
  • 15
  • 62
  • 137
-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…
-1
votes
1 answer

Load data from array variable to dictionary variable automatically in struct when data loaded from JSON in Swift

I wonder if is possible to load data from array variable to dictionary variable automatically in struct when data is loaded from JSON in Swift? Let say I have data which looks like below "values": [ { "name": "string", …
Pa Bloo
  • 51
  • 1
  • 3
-1
votes
1 answer

Creating Property Observers in Swift

I've been using Property Observers to manipulate UI and objects when a variable value has changed. With that in mind, I was wondering if it's possible to create my own Property Observers such as didSet and willSet for my own objects. what I'm…
HusseinB
  • 1,321
  • 1
  • 17
  • 41
1 2 3
4