ios - How can I get int values from the change dictionary in KVO method observeValueForKeyPath:ofObject:change:context:? -


i observing changes in rate property of avplayer calling following method on so:

addobserver:sharedplayermanagerinstance  forkeypath:@"rate"     options:nskeyvalueobservingoptionnew|nskeyvalueobservingoptionold     context:0];  

the change dictionary observevalueforkeypath:ofobject:change:context: therefore:

change = { kind: 1,             new: 1,             old: 0 } 

i checked class of each value, , turns out __nscfnumber. however, when try convert [change objectforkey:@"new"] or [change objectforkey:@"old"] int, nsinteger, nsnumber, tried nsstring, etc, works "old", gives me parsing error "new":

error: expected type error: 1 errors parsing expression 

i need compare them, , can't figure out. bug in ios?

objective c

-(void)observevalueforkeypath:(nsstring *)keypath ofobject:(id)object change:(nsdictionary *)change context:(void *)context{ nsnumber * newvalue = [change objectforkey:nskeyvaluechangenewkey]; nsinteger integervalue = newvalue.integervalue; int intvalue = newvalue.intvalue; } 

swift

   override func observevalueforkeypath(keypath: string, ofobject object: anyobject, change: [nsobject : anyobject], context: unsafemutablepointer<void>) {         if let newvalue = change[nskeyvaluechangenewkey] as? nsnumber{             let intvalue = newvalue.intvalue //to int         }     } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -