0

I just want to do something when the variable update value, and do not change the value. But the "get" is required if I implement "set", so I try to return the value self. It looks has already in "hell cycle":

var imageInfo:ImageInfo! {

    get {
        return self.imageInfo
    }
    set(info) {
        self.imageView.image = UIImage(named: info.fileName)
    }

}
Raymond Liao
  • 1,799
  • 3
  • 20
  • 32
  • 1
    Use `didSet` instead: http://stackoverflow.com/questions/24006234/what-is-the-purpose-of-willset-and-didset-in-swift. – Martin R Aug 22 '16 at 08:57

1 Answers1

0

If you want to do something when update the value, you should implement didSet method.

var imageInfo:ImageInfo! {

        didSet{
         // do your stuff here
         self.imageView.image = UIImage(named: imageInfo.fileName)
        }

}
Muzahid
  • 5,072
  • 2
  • 24
  • 42