sam
sam

Reputation: 359

Trigger a method when the value of the global variable changes?

I have defined a global variable, where it get updates frequently with accelerometer data, So i want to stop the accelerometer updates as soon as it's above 0.9, But it doesnt work like this way

if([ACCEL sharedInstance].accelval > 0.90f){
[self.motionManager stopAccelerometerUpdates];
}

Note: My accelerometer data gets updated, Do nothing wrong with the global variable thing! I call this inside -(void)viewDidLoad

Is there any other way to implement this? Thank you in advance!

Upvotes: 0

Views: 404

Answers (1)

parapura rajkumar
parapura rajkumar

Reputation: 24403

If you use a property instead of a variable you can use Key-Value Observing to observe changes to it

Upvotes: 2

Related Questions