iOS Guides | Samples

MonoTouch.Foundation.NSObjectFlag Class

Sentinel class used by the MonoTouch framework.

See Also: NSObjectFlag


public class NSObjectFlag


The sole purpose for the NSObjectFlag class is to be used as a sentinel in the NSObject class hierarchy to ensure that the actual object initialization only happens in NSObject.

When you chain your constructors using NSObjectFlag.Empty the only thing that will take place is the allocation of the object instance, no calls to any of the init: methods in base classes will be performed. If your code depends on this for initialization, you are responsible for calling the proper init method directly. For example:

c# Example

// The NSObjectFlag merely allocates the object and registers the
// C# class with the Objective-C runtime if necessary, but no actual
// initXxx method is invoked, that is done later in the constructor
// This is taken from MonoTouch's source code:
[Export ("initWithFrame:")]
public UIView (System.Drawing.RectangleF frame) : base (NSObjectFlag.Empty)
	// Invoke the init method now.
	var initWithFrame = new Selector ("initWithFrame:").Handle;
	if (IsDirectBinding) {
		Handle = MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSend_RectangleF (this.Handle, initWithFrame, frame);
	} else {
		Handle = MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_RectangleF (this.SuperHandle, initWithFrame, frame);

Alternatively, if you need a base class to initialize itself, you should call one of the other constructors that take some parameters.

c# Example

class MyViw : UIView {
	[Export ("initWithFrame:")]
	public MyView (RectangleF frame) : base (frame)
		// this initialized MyView by calling the UIView constructor
		// that initializes the object from a RectangleF frame.


Namespace: MonoTouch.Foundation
Assembly: monotouch (in monotouch.dll)
Assembly Versions:

The members of MonoTouch.Foundation.NSObjectFlag are listed below.

See Also: Object

Public Fields

static readonly
EmptyNSObjectFlag. Sentinel instance.