1

I want to add property observer to NSProgress. I have this code, but it calls only one time.

var progress: NSProgress?
{
    didSet
    {
        println(progress!.fractionCompleted)
    }
}
ChikabuZ
  • 10,031
  • 5
  • 63
  • 86

1 Answers1

3

The reason that your observer only fires once is that it's observing for changes on the progress variable itself, rather than properties within the progress variable (in this case, presumably fractionCompleted.) Since updated to the actual progress of your NSProgress don't involve you setting progress to a new NSProgress, you only hit the didSet once (presumably when you first instantiate it.)

The preferred pattern for observing changes to NSProgress is using Key-Value Observation, which will fit your use case much more nicely. You can read about it here.

jmduke
  • 1,657
  • 1
  • 13
  • 11