Share via


NSObject.AddObserver Method

Definition

Overloads

AddObserver(NSString, NSKeyValueObservingOptions, Action<NSObservedChange>)

Registers an object for being observed externally using an arbitrary method.

public IDisposable AddObserver(Foundation.NSString key, Foundation.NSKeyValueObservingOptions options, Action<Foundation.NSObservedChange> observer);
member this.AddObserver : Foundation.NSString * Foundation.NSKeyValueObservingOptions * Action<Foundation.NSObservedChange> -> IDisposable

Parameters

key
NSString

Key-path to use to perform the value lookup. The keypath consists of a series of lowercase ASCII-strings with no spaces in them separated by dot characters.

options
NSKeyValueObservingOptions

Flags indicating which notifications you are interested in receiving (New, Old, Initial, Prior).

observer
Action<NSObservedChange>

Method that will receive the observed changes.   It will receive a NSObservedChange parameter with the information that was changed.

Returns

An IDisposable object.  Invoke the Dispose method on this object to remove the observer.

Remarks

When the object is registered for observation, changes to the object specified in the keyPath that match the flags requested in options will be sent to the specied method (a lambda or method that matches the signature).

This version provides the convenience of exposing the changes as part of the strongly typed NSObservedChange object that is received by the target.

void Setup ()
{
    AddObserver (rateKey, NSKeyValueObservingOptions.Old | NSKeyValueObservingOptions.New, (observed) => {
        Console.WriteLine ("Change: {0}", observed.Change);
        Console.WriteLine ("NewValue: {0}", observed.NewValue);
        Console.WriteLine ("OldValue: {0}", observed.OldValue);
        Console.WriteLine ("Indexes: {0}", observed.Indexes);
        Console.WriteLine ("IsPrior: {0}", observed.IsPrior);
    });
}

Applies to

AddObserver(String, NSKeyValueObservingOptions, Action<NSObservedChange>)

Registers an object for being observed externally using an arbitrary method.

public IDisposable AddObserver(string key, Foundation.NSKeyValueObservingOptions options, Action<Foundation.NSObservedChange> observer);
member this.AddObserver : string * Foundation.NSKeyValueObservingOptions * Action<Foundation.NSObservedChange> -> IDisposable

Parameters

key
String

Key-path to use to perform the value lookup. The keypath consists of a series of lowercase ASCII-strings with no spaces in them separated by dot characters.

options
NSKeyValueObservingOptions

Flags indicating which notifications you are interested in receiving (New, Old, Initial, Prior).

observer
Action<NSObservedChange>

Method that will receive the observed changes.   It will receive a NSObservedChange parameter with the information that was changed.

Returns

An IDisposable object.  Invoke the Dispose method on this object to remove the observer.

Remarks

When the object is registered for observation, changes to the object specified in the keyPath that match the flags requested in options will be sent to the specied method (a lambda or method that matches the signature).

This version provides the convenience of exposing the changes as part of the strongly typed NSObservedChange object that is received by the target.

void Setup ()
{
    AddObserver (rateKey, NSKeyValueObservingOptions.Old | NSKeyValueObservingOptions.New, (observed) => {
        Console.WriteLine ("Change: {0}", observed.Change);
        Console.WriteLine ("NewValue: {0}", observed.NewValue);
        Console.WriteLine ("OldValue: {0}", observed.OldValue);
        Console.WriteLine ("Indexes: {0}", observed.Indexes);
        Console.WriteLine ("IsPrior: {0}", observed.IsPrior);
    });
}

Applies to

AddObserver(NSObject, NSString, NSKeyValueObservingOptions, IntPtr)

[Foundation.Export("addObserver:forKeyPath:options:context:")]
[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public virtual void AddObserver(Foundation.NSObject observer, Foundation.NSString keyPath, Foundation.NSKeyValueObservingOptions options, IntPtr context);
[<Foundation.Export("addObserver:forKeyPath:options:context:")>]
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
abstract member AddObserver : Foundation.NSObject * Foundation.NSString * Foundation.NSKeyValueObservingOptions * nativeint -> unit
override this.AddObserver : Foundation.NSObject * Foundation.NSString * Foundation.NSKeyValueObservingOptions * nativeint -> unit

Parameters

observer
NSObject
keyPath
NSString
context
IntPtr

nativeint

Attributes

Applies to

AddObserver(NSObject, String, NSKeyValueObservingOptions, IntPtr)

[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public void AddObserver(Foundation.NSObject observer, string keyPath, Foundation.NSKeyValueObservingOptions options, IntPtr context);
[<ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)>]
member this.AddObserver : Foundation.NSObject * string * Foundation.NSKeyValueObservingOptions * nativeint -> unit

Parameters

observer
NSObject
keyPath
String
context
IntPtr

nativeint

Attributes

Applies to