Questions tagged [didset]

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

See Property Observers in the The Swift Programming Language:

Property observers observe and respond to changes in a property’s value. Property observers are called every time a property’s value is set, even if the new value is the same as the property’s current value.

You can add property observers to any stored properties you define, apart from lazy stored properties. You can also add property observers to any inherited property (whether stored or computed) by overriding the property within a subclass. Property overriding is described in Overriding.

107 questions
0
votes
1 answer

Is it possible to make array empty without activating its DidSet property?

Currently I have an array that activates another function when set: var updatedBeaconDetailsArray = [BeaconDataDetails]() { didSet { self.updateBeaconData(beacon: self.updatedBeaconDetailsArray) } } I'm trying to clear the…
SwiftyJD
  • 5,257
  • 7
  • 41
  • 92
0
votes
1 answer

Observe changes in any property of any member of an array

I have an array which stores objects of a class: class Apple { var color = "Red" } let myApple = Apple() var apples = [Apple]() apples.append(myApple) // Func should be called here myApple.color = "Blue" let otherApple = Apple() // Func…
Luke
  • 965
  • 8
  • 21
0
votes
1 answer

Subclass of UIView doesn't invoke didSet

I have a subclass of UIView named BaseView. In subclass of BaseView I create didSet with some code. In UIViewController I init this subclass of BaseView and he doesn't invoke his didSet BaseView code: class BaseView: UIView { override…
Akizsura
  • 3
  • 2
0
votes
1 answer

Set didSet for outlet collection

I have a few picker view that I added in a outlet collection, they should have different properties that I need to add them in their didset for example, here is the outlet collection @IBOutlet var dataPickers: [UIPickerView]! { didset { …
JOnney
  • 89
  • 1
  • 8
0
votes
1 answer

Adding a target to UIButton in UITableViewCell with didSet

I am trying to refactor my code and I can't seem to active the handleFavoriteStar() action from the SearchController when the button is tapped. I was following this video by LBTA on refactoring: https://youtu.be/F3snOdQ5Qyo Formula Cell: class…
Juan
  • 233
  • 2
  • 7
0
votes
3 answers

I am trying to pass a value from a UICollectionView Item to a UIButton in Swift 4

I have a UICollectionViewCell. This Cell is registered in another UICollectionViewCell, which in turn is registered in viewDidLoad of a UIViewController called FilterCollectionViewController. When the first cell is selected it should pass a value of…
0
votes
0 answers

object value doesn't change after didset

I am using some cocoa pods frame to make UICollectionView. I am able to get the right data for each cell and setup views. I want to have different ani The animation end point should be related to the value of dataSource.The problem is that I can't…
anergy7
  • 1
  • 5
0
votes
3 answers

Why do we can return from didSet property observer

When I create a recursion in a didSet actually I turned out i could just put a return and program exits from didSet . But i did not find anywhere (i was searching for a long time) that i can put a return word to exit from didSet. So, is didSet works…
Ninja
  • 309
  • 7
  • 26
0
votes
0 answers

Use didSet while initialising a variable

I have one array results which I am using to set another array filteredResult which contains some filtered value of the main results array. var filteredResult: [Result] { var result = self.results.filter({ $0.exclusive == true }) result =…
Arnab
  • 4,216
  • 2
  • 28
  • 50
0
votes
1 answer

Is there any way to invoke "didSet" of object from within the object itself?

I have this code: class Child { var data : String?; func updateData (s: String) { data = s; } } class Parent { var tableView : UITableView? var child : Child? { didSet { tableView.reloadData(); } } func updateChild {…
Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124
0
votes
2 answers

Issue in notifying using didSet

I have a collection view with images. Each collection view item has the image & other data associated with them like 'grand_total', 'product_id' etc. Now each collection view item has a button & when I click on it, the values like grand_total etc.…
user8653398
0
votes
2 answers

Issue with setting didSet

I am getting image from a url using SDWebImage and assigning it to an array like so... let imgUrl = arrProduct?[indexPath.section].images[indexPath.row].url let placeholderImage = UIImage(named:…
user8653398
0
votes
1 answer

didSet is always called when initializing a UITableViewCell

I have a custom UITableViewCell with the following: a computed property called quantityCount with didSet. Array. didSet has a condition, if the current quantityCount > oldValue, I will increase append to my array. if the oldValue > quantityCount I…
Ennabah
  • 2,303
  • 2
  • 20
  • 39
0
votes
2 answers

Listen for updates in the data model array when one of its properties changes

I have a custom UITableViewCell which has a data model array, and a UILabel as this: class ItemCustomizationCollectionViewCell: UITableViewCell { var customizationData: CustomizationData? let priceLabel: UILabel = { let label =…
Ennabah
  • 2,303
  • 2
  • 20
  • 39
0
votes
0 answers

Swift didSet to initialize owner causing leak

Why the code cause memory leak when give a new userInfo? How to fix it? var viewModel: MineViewModel = MineViewModel(userInfo: nil) var userInfo: UserInfo? { didSet { viewModel = MineViewModel(userInfo: userInfo) } }
huangxinyu
  • 247
  • 3
  • 11