<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCell",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCell"
  },
  "title" : "NSCell"
}
-->

# NSCell

A mechanism for displaying text or images in a view object without the overhead of a full [`NSView`](/documentation/AppKit/NSView) subclass.

```
@MainActor class NSCell
```

## Overview

Cells are used by most of the [`NSControl`](/documentation/AppKit/NSControl) classes to implement their internal workings.

### Designated Initializers

When subclassing `NSCell` you must implement all of the designated initializers. Those methods include [`init()`](/documentation/AppKit/NSCell/init()), [`init(coder:)`](/documentation/AppKit/NSCell/init(coder:)), [`init(textCell:)`](/documentation/AppKit/NSCell/init(textCell:)), and [`init(imageCell:)`](/documentation/AppKit/NSCell/init(imageCell:)).

## Topics

### Initializing a Cell

[`init(imageCell: NSImage?)`](/documentation/AppKit/NSCell/init(imageCell:))

Returns an `NSCell` object initialized with the specified image and set to have the cell’s default menu.

[`init(textCell: String)`](/documentation/AppKit/NSCell/init(textCell:))

Returns an NSCell object initialized with the specified string and set to have the cell’s default menu.

### Managing Cell Values

[`var objectValue: Any?`](/documentation/AppKit/NSCell/objectValue)

The cell’s value as an Objective-C object.

[`var hasValidObjectValue: Bool`](/documentation/AppKit/NSCell/hasValidObjectValue)

A Boolean value that indicates whether the cell has a valid object value.

[`var intValue: Int32`](/documentation/AppKit/NSCell/intValue)

The cell’s value as an integer.

[`var integerValue: Int`](/documentation/AppKit/NSCell/integerValue)

The cell’s value as an integer value.

[`var stringValue: String`](/documentation/AppKit/NSCell/stringValue)

The cell’s value as a string.

[`var doubleValue: Double`](/documentation/AppKit/NSCell/doubleValue)

The cell’s value as a double-precision floating-point number.

[`var floatValue: Float`](/documentation/AppKit/NSCell/floatValue)

The cell’s value as a single-precision floating-point number.

### Managing Cell Attributes

[`func setCellAttribute(NSCell.Attribute, to: Int)`](/documentation/AppKit/NSCell/setCellAttribute(_:to:))

Sets the value for the specified cell attribute.

[`func cellAttribute(NSCell.Attribute) -> Int`](/documentation/AppKit/NSCell/cellAttribute(_:))

Returns the value for the specified cell attribute.

[`var type: NSCell.CellType`](/documentation/AppKit/NSCell/type)

The type of the cell.

[`var isEnabled: Bool`](/documentation/AppKit/NSCell/isEnabled)

A Boolean value indicating whether the cell is currently enabled.

[`var allowsUndo: Bool`](/documentation/AppKit/NSCell/allowsUndo)

A Boolean value indicating whether the cell assumes responsibility for undo operations.

### Managing Display Attributes

[`var isBezeled: Bool`](/documentation/AppKit/NSCell/isBezeled)

A Boolean value indicating whether the cell has a bezeled border.

[`var isBordered: Bool`](/documentation/AppKit/NSCell/isBordered)

A Boolean value indicating whether the cell draws itself outlined with a plain border.

[`var isOpaque: Bool`](/documentation/AppKit/NSCell/isOpaque)

A Boolean value indicating whether the cell is completely opaque.

[`var controlTint: NSControlTint`](/documentation/AppKit/NSCell/controlTint)

The cell’s control tint.

[`var backgroundStyle: NSView.BackgroundStyle`](/documentation/AppKit/NSCell/backgroundStyle)

The cell’s background style.

[`var interiorBackgroundStyle: NSView.BackgroundStyle`](/documentation/AppKit/NSCell/interiorBackgroundStyle)

The cell’s interior background style.

[`enum BackgroundStyle`](/documentation/AppKit/NSView/BackgroundStyle)

Background styles to apply to a view’s cell.

### Managing Cell State

[`var allowsMixedState: Bool`](/documentation/AppKit/NSCell/allowsMixedState)

A Boolean value indicating whether the cell supports three states instead of two.

[`var nextState: Int`](/documentation/AppKit/NSCell/nextState)

The cell’s next state.

[`func setNextState()`](/documentation/AppKit/NSCell/setNextState())

Changes cell’s state to the next value in the sequence.

[`var state: NSControl.StateValue`](/documentation/AppKit/NSCell/state)

The cell’s current state.

[`struct StateValue`](/documentation/AppKit/NSControl/StateValue)

A constant that indicates whether a control is on, off, or in a mixed state.

### Modifying Textual Attributes

[`var isEditable: Bool`](/documentation/AppKit/NSCell/isEditable)

A Boolean value indicating whether the cell is editable.

[`var isSelectable: Bool`](/documentation/AppKit/NSCell/isSelectable)

A Boolean value indicating whether the cell’s text can be selected.

[`var isScrollable: Bool`](/documentation/AppKit/NSCell/isScrollable)

A Boolean value indicating whether excess text scrolls past the cell’s bounds.

[`var alignment: NSTextAlignment`](/documentation/AppKit/NSCell/alignment)

The alignment of the cell’s text.

[`var font: NSFont?`](/documentation/AppKit/NSCell/font)

The font that the cell uses to display text.

[`var lineBreakMode: NSLineBreakMode`](/documentation/AppKit/NSCell/lineBreakMode)

The line break mode to use when drawing text in the cell.

[`var truncatesLastVisibleLine: Bool`](/documentation/AppKit/NSCell/truncatesLastVisibleLine)

A Boolean value indicating whether the cell truncates text that does not fit within the cell’s bounds.

[`var wraps: Bool`](/documentation/AppKit/NSCell/wraps)

A Boolean value indicating whether the cell wraps text whose length that exceeds the cell’s frame.

[`var baseWritingDirection: NSWritingDirection`](/documentation/AppKit/NSCell/baseWritingDirection)

The initial writing direction used to determine the actual writing direction for text.

[`var attributedStringValue: NSAttributedString`](/documentation/AppKit/NSCell/attributedStringValue)

The cell’s value as an attributed string.

[`var allowsEditingTextAttributes: Bool`](/documentation/AppKit/NSCell/allowsEditingTextAttributes)

A Boolean value indicating whether the cell allows the editing of its content’s text attributes by the user.

[`var importsGraphics: Bool`](/documentation/AppKit/NSCell/importsGraphics)

A Boolean value indicating whether the cell supports the importation of images into its text.

[`func setUpFieldEditorAttributes(NSText) -> NSText`](/documentation/AppKit/NSCell/setUpFieldEditorAttributes(_:))

Configures the textual and background attributes of the receiver’s field editor.

[`var title: String`](/documentation/AppKit/NSCell/title)

The cell’s title text.

### Managing the Target and Action

[`var action: Selector?`](/documentation/AppKit/NSCell/action)

The action performed by the cell.

[`var target: AnyObject?`](/documentation/AppKit/NSCell/target)

The object that receives the cell’s action messages.

[`var isContinuous: Bool`](/documentation/AppKit/NSCell/isContinuous)

A Boolean value indicating whether the cell sends its action message continuously during mouse tracking.

[`func sendAction(on: NSEvent.EventTypeMask) -> Int`](/documentation/AppKit/NSCell/sendAction(on:))

Sets the conditions on which the receiver sends action messages to its target.

### Managing the Image

[`var image: NSImage?`](/documentation/AppKit/NSCell/image)

The image displayed by the cell, if any.

### Managing the Tag

[`var tag: Int`](/documentation/AppKit/NSCell/tag)

A tag for identifying the cell.

### Formatting and Validating Data

[`var formatter: Formatter?`](/documentation/AppKit/NSCell/formatter)

The cell’s formatter object.

### Managing Menus

[`class var defaultMenu: NSMenu?`](/documentation/AppKit/NSCell/defaultMenu)

Returns the default menu for instances of the cell.

[`var menu: NSMenu?`](/documentation/AppKit/NSCell/menu)

The cell’s contextual menu.

[`func menu(for: NSEvent, in: NSRect, of: NSView) -> NSMenu?`](/documentation/AppKit/NSCell/menu(for:in:of:))

Returns the menu associated with the cell and related to the specified event and frame.

### Comparing Cells

[`func compare(Any) -> ComparisonResult`](/documentation/AppKit/NSCell/compare(_:))

Compares the string values of the receiver another cell, disregarding case.

### Respond to Keyboard Events

[`var acceptsFirstResponder: Bool`](/documentation/AppKit/NSCell/acceptsFirstResponder)

A Boolean value indicating whether the cell accepts first responder status.

[`var showsFirstResponder: Bool`](/documentation/AppKit/NSCell/showsFirstResponder)

A Boolean value indicating whether the cell provides a visual indication that it is the first responder.

[`var refusesFirstResponder: Bool`](/documentation/AppKit/NSCell/refusesFirstResponder)

A Boolean value indicating whether the cell refuses the first responder status.

[`func performClick(Any?)`](/documentation/AppKit/NSCell/performClick(_:))

Simulates a single mouse click on the receiver.

### Deriving Values

[`func takeObjectValueFrom(Any?)`](/documentation/AppKit/NSCell/takeObjectValueFrom(_:))

Sets the value of the receiver’s cell to the object value obtained from the specified object.

[`func takeIntegerValueFrom(Any?)`](/documentation/AppKit/NSCell/takeIntegerValueFrom(_:))

Sets the value of the receiver’s cell to an integer value obtained from the specified object.

[`func takeIntValueFrom(Any?)`](/documentation/AppKit/NSCell/takeIntValueFrom(_:))

Sets the value of the receiver’s cell to an integer value obtained from the specified object.

[`func takeStringValueFrom(Any?)`](/documentation/AppKit/NSCell/takeStringValueFrom(_:))

Sets the value of the receiver’s cell to the string value obtained from the specified object.

[`func takeDoubleValueFrom(Any?)`](/documentation/AppKit/NSCell/takeDoubleValueFrom(_:))

Sets the value of the receiver’s cell to a double-precision floating-point value obtained from the specified object.

[`func takeFloatValueFrom(Any?)`](/documentation/AppKit/NSCell/takeFloatValueFrom(_:))

Sets the value of the receiver’s cell to a single-precision floating-point value obtained from the specified object.

### Representing an Object

[`var representedObject: Any?`](/documentation/AppKit/NSCell/representedObject)

The object represented by the cell.

### Tracking the Mouse

[`func trackMouse(with: NSEvent, in: NSRect, of: NSView, untilMouseUp: Bool) -> Bool`](/documentation/AppKit/NSCell/trackMouse(with:in:of:untilMouseUp:))

Initiates the mouse tracking behavior in a cell.

[`func startTracking(at: NSPoint, in: NSView) -> Bool`](/documentation/AppKit/NSCell/startTracking(at:in:))

Begins tracking mouse events within the receiver.

[`func continueTracking(last: NSPoint, current: NSPoint, in: NSView) -> Bool`](/documentation/AppKit/NSCell/continueTracking(last:current:in:))

Returns a Boolean value that indicates whether mouse tracking should continue in the receiving cell.

[`func stopTracking(last: NSPoint, current: NSPoint, in: NSView, mouseIsUp: Bool)`](/documentation/AppKit/NSCell/stopTracking(last:current:in:mouseIsUp:))

Stops tracking mouse events within the receiver.

[`var mouseDownFlags: Int`](/documentation/AppKit/NSCell/mouseDownFlags)

The modifier flags for the last (left) mouse-down event.

[`class var prefersTrackingUntilMouseUp: Bool`](/documentation/AppKit/NSCell/prefersTrackingUntilMouseUp)

Returns a Boolean value that indicates whether tracking stops when the cursor leaves the cell.

[`func getPeriodicDelay(UnsafeMutablePointer<Float>, interval: UnsafeMutablePointer<Float>)`](/documentation/AppKit/NSCell/getPeriodicDelay(_:interval:))

Returns the initial delay and repeat values for continuous sending of action messages to target objects.

### Hit Testing

[`func hitTest(for: NSEvent, in: NSRect, of: NSView) -> NSCell.HitResult`](/documentation/AppKit/NSCell/hitTest(for:in:of:))

Returns hit testing information for the receiver.

### Managing the Cursor

[`func resetCursorRect(NSRect, in: NSView)`](/documentation/AppKit/NSCell/resetCursorRect(_:in:))

Sets the receiver to show the I-beam cursor while it tracks the mouse.

### Handling Keyboard Alternatives

[`var keyEquivalent: String`](/documentation/AppKit/NSCell/keyEquivalent)

The key equivalent associated with clicking the cell.

### Dragging Cells

[`func draggingImageComponents(withFrame: NSRect, in: NSView) -> [NSDraggingImageComponent]`](/documentation/AppKit/NSCell/draggingImageComponents(withFrame:in:))

Generates dragging image components with the specified frame in the view.

### Managing Focus Rings

[`func drawFocusRingMask(withFrame: NSRect, in: NSView)`](/documentation/AppKit/NSCell/drawFocusRingMask(withFrame:in:))

Draws the focus ring for the control.

[`func focusRingMaskBounds(forFrame: NSRect, in: NSView) -> NSRect`](/documentation/AppKit/NSCell/focusRingMaskBounds(forFrame:in:))

Returns the bounds of the focus ring mask.

[`class var defaultFocusRingType: NSFocusRingType`](/documentation/AppKit/NSCell/defaultFocusRingType)

Returns the default type of focus ring for the receiver.

[`var focusRingType: NSFocusRingType`](/documentation/AppKit/NSCell/focusRingType)

The type of focus ring to use with the associated view.

### Determining Cell Size

[`func calcDrawInfo(NSRect)`](/documentation/AppKit/NSCell/calcDrawInfo(_:))

Recalculates the cell geometry.

[`var cellSize: NSSize`](/documentation/AppKit/NSCell/cellSize)

The minimum size needed to display the cell.

[`func cellSize(forBounds: NSRect) -> NSSize`](/documentation/AppKit/NSCell/cellSize(forBounds:))

Returns the minimum size needed to display the receiver, constraining it to the specified rectangle.

[`func drawingRect(forBounds: NSRect) -> NSRect`](/documentation/AppKit/NSCell/drawingRect(forBounds:))

Returns the rectangle within which the receiver draws itself

[`func imageRect(forBounds: NSRect) -> NSRect`](/documentation/AppKit/NSCell/imageRect(forBounds:))

Returns the rectangle in which the receiver draws its image.

[`func titleRect(forBounds: NSRect) -> NSRect`](/documentation/AppKit/NSCell/titleRect(forBounds:))

Returns the rectangle in which the receiver draws its title text.

[`var controlSize: NSControl.ControlSize`](/documentation/AppKit/NSCell/controlSize)

The size of the cell.

### Drawing and Highlighting

[`func draw(withFrame: NSRect, in: NSView)`](/documentation/AppKit/NSCell/draw(withFrame:in:))

Draws the receiver’s border and then draws the interior of the cell.

[`func highlightColor(withFrame: NSRect, in: NSView) -> NSColor?`](/documentation/AppKit/NSCell/highlightColor(withFrame:in:))

Returns the color the receiver uses when drawing the selection highlight.

[`func drawInterior(withFrame: NSRect, in: NSView)`](/documentation/AppKit/NSCell/drawInterior(withFrame:in:))

Draws the interior portion of the receiver, which includes the image or text portion but does not include the border.

[`var controlView: NSView?`](/documentation/AppKit/NSCell/controlView)

The view associated with the cell.

[`func highlight(Bool, withFrame: NSRect, in: NSView)`](/documentation/AppKit/NSCell/highlight(_:withFrame:in:))

Redraws the receiver with the specified highlight setting.

[`var isHighlighted: Bool`](/documentation/AppKit/NSCell/isHighlighted)

A Boolean value indicating whether the cell has a highlighted appearance.

### Editing and Selecting Text

[`func edit(withFrame: NSRect, in: NSView, editor: NSText, delegate: Any?, event: NSEvent?)`](/documentation/AppKit/NSCell/edit(withFrame:in:editor:delegate:event:))

Begins editing of the receiver’s text using the specified field editor.

[`func select(withFrame: NSRect, in: NSView, editor: NSText, delegate: Any?, start: Int, length: Int)`](/documentation/AppKit/NSCell/select(withFrame:in:editor:delegate:start:length:))

Selects the specified text range in the cell’s field editor.

[`var sendsActionOnEndEditing: Bool`](/documentation/AppKit/NSCell/sendsActionOnEndEditing)

A Boolean value indicating whether the cell’s control object sends its action message when the user finishes editing the cell’s text.

[`func endEditing(NSText)`](/documentation/AppKit/NSCell/endEditing(_:))

Ends the editing of text in the receiver using the specified field editor.

[`var wantsNotificationForMarkedText: Bool`](/documentation/AppKit/NSCell/wantsNotificationForMarkedText)

A Boolean value indicating whether the cell’s field editor should post text change notifications.

[`func fieldEditor(for: NSView) -> NSTextView?`](/documentation/AppKit/NSCell/fieldEditor(for:))

Returns a custom field editor for editing in the view.

[`var usesSingleLineMode: Bool`](/documentation/AppKit/NSCell/usesSingleLineMode)

A Boolean value indicating whether the cell restricts layout and rendering of text to a single line.

### Managing Expansion Frames

[`func expansionFrame(withFrame: NSRect, in: NSView) -> NSRect`](/documentation/AppKit/NSCell/expansionFrame(withFrame:in:))

Returns the expansion cell frame for the receiver.

[`func draw(withExpansionFrame: NSRect, in: NSView)`](/documentation/AppKit/NSCell/draw(withExpansionFrame:in:))

Instructs the receiver to draw in an expansion frame.

### User Interface Layout Direction

[`var userInterfaceLayoutDirection: NSUserInterfaceLayoutDirection`](/documentation/AppKit/NSCell/userInterfaceLayoutDirection)

The layout direction of the user interface.

### Constants

[`enum CellType`](/documentation/AppKit/NSCell/CellType)

Constants for specifying how a cell represents its data (as text or as an image).

[`enum Attribute`](/documentation/AppKit/NSCell/Attribute)

Constants for specifying how a button behaves when pressed and how it displays its state.

[`enum ImagePosition`](/documentation/AppKit/NSControl/ImagePosition)

A constant for specifying the position of a button’s image relative to its title.

[`enum NSImageScaling`](/documentation/AppKit/NSImageScaling)

Constants that specify a cell’s image scaling behavior.

[`typealias StateValue`](/documentation/AppKit/NSCell/StateValue)

Constants for specifying a cell’s state and are used mostly for buttons.

[`struct StyleMask`](/documentation/AppKit/NSCell/StyleMask)

Constants for specifying what happens when a button is pressed or is displaying its alternate state.

[`enum NSControlTint`](/documentation/AppKit/NSControlTint)

Constants for specifying a cell’s tint color.

[`enum ControlSize`](/documentation/AppKit/NSControl/ControlSize-swift.enum)

A constant for specifying a cell’s size.

[`struct HitResult`](/documentation/AppKit/NSCell/HitResult)

Constants used by the [`hitTest(for:in:of:)`](/documentation/AppKit/NSCell/hitTest(for:in:of:)) method to determine the effect of an event.

[`enum BackgroundStyle`](/documentation/AppKit/NSView/BackgroundStyle)

Background styles to apply to a view’s cell.

[Deprecated Scaling Constants](/documentation/AppKit/deprecated-scaling-constants)

These are deprecated scaling constants.

[Data Entry Types](/documentation/AppKit/data-entry-types)

These constants specify how a cell formats numeric data.

### Notifications

[`class let currentControlTintDidChangeNotification: NSNotification.Name`](/documentation/AppKit/NSColor/currentControlTintDidChangeNotification)

Sent after the user changes control tint preference.

### Deprecated Methods

[`- (void) setEntryType:(NSInteger) type;`](/documentation/AppKit/NSCell/setEntryType:)

Sets how numeric data is formatted in the receiver and places restrictions on acceptable input.

[`- (NSInteger) entryType;`](/documentation/AppKit/NSCell/entryType)

Returns the type of data the user can type into the receiver.

[`- (BOOL) isEntryAcceptable:(NSString *) string;`](/documentation/AppKit/NSCell/isEntryAcceptable:)

Returns whether a string representing a numeric or date value is formatted in a suitable way for the cell’s entry type.

[`- (void) setFloatingPointFormat:(BOOL) autoRange left:(NSUInteger) leftDigits right:(NSUInteger) rightDigits;`](/documentation/AppKit/NSCell/setFloatingPointFormat:left:right:)

Sets the auto-ranging and floating point number format of the receiver’s cell.

[`- (void) setTitleWithMnemonic:(NSString *) stringWithAmpersand;`](/documentation/AppKit/NSCell/setTitleWithMnemonic:)

Sets the title of the receiver with one character in the string denoted as an access key.

[`- (NSString *) mnemonic;`](/documentation/AppKit/NSCell/mnemonic)

Returns the character in the receiver’s title that appears underlined for use as a mnemonic.

[`- (void) setMnemonicLocation:(NSUInteger) location;`](/documentation/AppKit/NSCell/setMnemonicLocation:)

Sets the character of the receiver’s title to be used as a mnemonic character.

[`- (NSUInteger) mnemonicLocation;`](/documentation/AppKit/NSCell/mnemonicLocation)

Returns the position of the underlined mnemonic character in the receiver’s title.

### Initializers

[`init()`](/documentation/AppKit/NSCell/init())

[`init(coder: NSCoder)`](/documentation/AppKit/NSCell/init(coder:))

## Relationships

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSAccessibilityElementProtocol`](/documentation/AppKit/NSAccessibilityElementProtocol)

[`Equatable`](/documentation/Swift/Equatable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSUserInterfaceItemIdentification`](/documentation/AppKit/NSUserInterfaceItemIdentification)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Sendable`](/documentation/Swift/Sendable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSAccessibilityProtocol`](/documentation/AppKit/NSAccessibilityProtocol)

[`Hashable`](/documentation/Swift/Hashable)

[`NSCopying`](/documentation/Foundation/NSCopying)

### Inherited By

[`NSActionCell`](/documentation/AppKit/NSActionCell)

[`NSTextAttachmentCell-swift.class`](/documentation/AppKit/NSTextAttachmentCell-swift.class)

[`NSImageCell`](/documentation/AppKit/NSImageCell)

[`NSBrowserCell`](/documentation/AppKit/NSBrowserCell)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)