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)
}
}
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)
}
}
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.