Last active
August 29, 2015 14:03
-
-
Save rzaitov/bfb3c273e4e6e2c8bc64 to your computer and use it in GitHub Desktop.
Dependent key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class MyController : UIViewController | |
{ | |
private bool deviceAuthorized { | |
[Export("isDeviceAuthorized")] | |
get; | |
[Export("setDeviceAuthorized:")] | |
set; | |
} | |
private bool sessionRunningAndDeviceAuthorized { | |
[Export("isSessionRunningAndDeviceAuthorized")] | |
get { | |
return deviceAuthorized; | |
} | |
} | |
[Export("keyPathsForValuesAffectingSessionRunningAndDeviceAuthorized")] | |
private static NSSet keyPathsForValuesAffectingSessionRunningAndDeviceAuthorized () | |
{ | |
return NSSet.MakeNSObjectSet (new NSString[] { | |
(NSString)"deviceAuthorized", | |
}); | |
} | |
public override void ViewWillAppear (bool animated) | |
{ | |
base.ViewWillAppear (animated); | |
NSKeyValueObservingOptions oldNew = NSKeyValueObservingOptions.Old | NSKeyValueObservingOptions.New; | |
NSKeyValueObservingOptions initOldNew = NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.Old | NSKeyValueObservingOptions.New; | |
AddObserver (this, (NSString)"sessionRunningAndDeviceAuthorized", oldNew, SessionRunningAndDeviceAuthorizedContext); | |
// after this call I expect ObserveValue method invokation. | |
deviceAuthorized = !deviceAuthorized; | |
} | |
public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found solution, but I think it is not great.
I can surround deviceAuthorized = !deviceAuthorized; with WillChangeValue / DidChangeValue:
But why [Export()] doesn't do all job?