Protocol

NSAccessibility

The complete list of properties and methods implemented by accessible elements.

Overview

In general, your custom user interface elements should not adopt this protocol. Instead, select the role-specific protocol—such as NSAccessibilityButton, NSAccessibilityImage, or NSAccessibilityGroup—that best matches your element’s behavior.

By default, many AppKit classes already adopt the NSAccessibility protocol. In particular, NSView, NSWindow, NSCell and NSDrawer) provide a default implementation for all the properties and methods listed in this protocol. However, if you create a custom subclass that adopts one of the role-specific protocols, the compiler may ask you to reimplement some of the protocol’s accessor or action methods. By forcing you to reimplement these methods, the compiler helps ensure that your custom subclass provides accurate information to the accessibility clients.

If your custom user interface element does not inherit from NSView (or one of the other accessibility-enabled AppKit classes), subclass the NSAccessibilityElement class instead. This class manages many of the details required to work with accessibility clients successfully. You also need to implement all the properties and methods from your user interface element’s role-specific protocol—as well as any additional properties and methods you may need to use to further customize your element’s behavior.

Customizing User Interface Elements

You can further customize any user interface elements by freely implementing any of the other properties or methods listed in the NSAccessibility protocol. You do not need to adopt any particular protocol to make these properties and methods available to the accessibility client. As soon as your element is accessibility enabled, the system automatically uses any of the NSAccessibility properties and methods that you have implemented.

If a user interface element inherits from NSView (or one of the other accessibility-enabled AppKit classes), you can also customize it by simply setting the appropriate properties. Often, you can fine tune how an accessibility client interacts with your element without creating a custom subclass.

Sometimes, however, it makes more sense to override the property’s accessor methods. If you override the getter for a property declared in the NSAccessibility protocol, the system lets accessibility clients call your getter. This can be particularly useful when managing dynamic properties, because you can calculate their current value on demand instead of trying to update the property in response to a change.

If you override the setter for a property, by default the system lets accessibility clients both read and modify that property. For example, you can override the setter for a control’s accessibilityValue property, letting users modify the control’s value through an accessibility client.

You can further control which accessor methods the accessibility client can use by overriding isAccessibilitySelectorAllowed(_:). Return true if the accessibility client can call the selector; otherwise, false.

Topics

Text-Specific Properties and Methods

func accessibilityString(for: NSRange)

Returns the substring for the specified range.

Required.

func accessibilityAttributedString(for: NSRange)

Returns the attributed substring for the specified range of characters.

Required.

func accessibilityRTF(for: NSRange)

Returns the Rich Text Format (RTF) data that describes the specified range of characters.

Required.

func accessibilityFrame(for: NSRange)

Returns the rectangle enclosing the specified range of characters.

Required.

func accessibilityLine(for: Int)

Returns the line number for the line holding the specified character index.

Required.

func accessibilityRange(for: Int)

Returns the range of characters for the glyph that includes the specified character.

Required.

func accessibilityStyleRange(for: Int)

Returns a range of characters that all have the same style as the specified character.

Required.

func accessibilityRange(forLine: Int)

Returns the range of characters in the specified line.

Required.

func accessibilityRange(for: NSPoint)

Returns the range of characters for the glyph at the specified point.

Required.

Cell-Based Table Properties and Methods

func accessibilityCell(forColumn: Int, row: Int)

The cell at the specified column and row.

Required.

Layout Properties and Methods

func accessibilityLayoutPoint(forScreenPoint: NSPoint)

Converts the provided point in screen coordinates to a point in the layout area’s coordinate system.

Required.

func accessibilityLayoutSize(forScreenSize: NSSize)

Converts the provided size in screen coordinates to a size in the layout area’s coordinate system.

Required.

func accessibilityScreenPoint(forLayoutPoint: NSPoint)

Converts the provided point in the layout area’s coordinates to a point in the screen’s coordinate system.

Required.

func accessibilityScreenSize(forLayoutSize: NSSize)

Converts the provided size in the layout area’s coordinates to a size in the screen’s coordinate system.

Required.

Action Methods

func accessibilityPerformCancel()

Cancels the current operation.

Required.

func accessibilityPerformConfirm()

Simulates pressing Return in the element.

Required.

func accessibilityPerformDecrement()

Decrements the element’s value.

Required.

func accessibilityPerformDelete()

Deletes the element’s value.

Required.

func accessibilityPerformIncrement()

Increments the element’s value.

Required.

func accessibilityPerformPick()

Selects the element.

Required.

func accessibilityPerformPress()

Simulates clicking the element.

Required.

func accessibilityPerformRaise()

Brings this window to the front.

Required.

func accessibilityPerformShowAlternateUI()

Displays the element’s alternate UI.

Required.

func accessibilityPerformShowDefaultUI()

Returns to the element’s original UI.

Required.

func accessibilityPerformShowMenu()

Displays this menu element.

Required.

func isAccessibilitySelectorAllowed(Selector)

Indicates whether the provided selector can be invoked on the element.

Required.

Constants

enum NSAccessibilitySortDirection

Values that indicate the sort direction of a column (used with the accessibilitySortDirection property).

enum NSAccessibilityUnits

Values that indicate the unit values of a ruler or layout area (used with the accessibilityHorizontalUnits, accessibilityVerticalUnits, and accessibilityUnits properties).

enum NSAccessibilityPriorityLevel

A data type for notification priority levels.

Notification Priority Levels

Values for specifying the priority level of a notification.

enum NSAccessibilityOrientation

Values that indicate the orientation of elements, such as scroll bars and split views. Use these values with an accessibility element’s accessibilityOrientation property.

Roles

Standard roles that identify the type of object that an accessibility element represents. Use these constants with an accessibility element’s accessibilityRole property.

enum NSAccessibilityRulerMarkerType

Values that indicate the marker type of an element. Use these values with an accessibility element’s accessibilityRulerMarkerType property.

Subroles

Subroles identify a specialized object subtype that an accessibility element represents. Use these constants with an accessibility element’s accessibilitySubrole property.

UserInfo Key for Error Codes in Accessibility Exceptions

A key used by the userInfo dictionary of an NSAccessibilityException.

UserInfo Keys for Posting Accessibility Notifications

Keys used by the userInfo dictionary of an accessibility notification posted using the NSAccessibilityPostNotificationWithUserInfo(_:_:_:) function.

Notifications

These notifications alert accessibility clients to changes in the user interface’s state. This lets the accessibility client present these changes to the user. AppKit classes automatically post notifications for their basic behaviors; however, you may need to post your own notifications if you want to modify a class’s behavior, or if you are implementing a custom accessibility element. Always send these notifications using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let announcementRequested: NSAccessibilityNotificationName

This notification is posted whenever an accessibility element needs to make an announcement to the user. This notification requires a userInfo dictionary with the key announcement and a localized string containing the announcement. To help an assistive app determine the importance of the announcement, add the appropriate priority to the userInfo dictionary.

static let applicationActivated: NSAccessibilityNotificationName

This notification is posted after the app has been activated. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let applicationDeactivated: NSAccessibilityNotificationName

This notification is posted after the app has been deactivated. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let applicationHidden: NSAccessibilityNotificationName

This notification is posted after the app is hidden. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let applicationShown: NSAccessibilityNotificationName

This notification is posted after the app is shown. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let created: NSAccessibilityNotificationName

This notification is posted after an accessibility element is created. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let drawerCreated: NSAccessibilityNotificationName

This notification is posted after a drawer appears. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let focusedUIElementChanged: NSAccessibilityNotificationName

This notification is posted after an accessibility element gains focus. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let focusedWindowChanged: NSAccessibilityNotificationName

This notification is posted after the key window changes. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let helpTagCreated: NSAccessibilityNotificationName

This notification is posted after a help tag appears. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let layoutChanged: NSAccessibilityNotificationName

This notification is posted after the UI changes in a way that requires the attention of an accessibility client. This notification should be accompanied by a userInfo dictionary with the key uiElements and an array containing the UI elements that have been added or changed. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let mainWindowChanged: NSAccessibilityNotificationName

This notification is posted after the main window changes. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let moved: NSAccessibilityNotificationName

This notification is posted after an accessibility element moves. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let resized: NSAccessibilityNotificationName

This notification is posted after an accessibility element’s size changes. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let rowCollapsed: NSAccessibilityNotificationName

This notification is posted after a row collapses. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let rowCountChanged: NSAccessibilityNotificationName

This notification is posted after a row is added or deleted. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let rowExpanded: NSAccessibilityNotificationName

This notification is posted after a row expands. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let selectedCellsChanged: NSAccessibilityNotificationName

This notification is posted after one or more cells in a cell-based table are selected or deselected. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let selectedChildrenChanged: NSAccessibilityNotificationName

This notification is posted after one or more child elements are selected or deselected. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let selectedChildrenMoved: NSAccessibilityNotificationName

This notification is posted after the selected items in a layout area move. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let selectedColumnsChanged: NSAccessibilityNotificationName

This notification is posted after one or more columns are selected or deselected. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let selectedRowsChanged: NSAccessibilityNotificationName

This notification is posted after one or more rows are selected or deselected. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let selectedTextChanged: NSAccessibilityNotificationName

This notification is posted after text is selected or deselected. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let sheetCreated: NSAccessibilityNotificationName

This notification is posted after a sheet appears. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let titleChanged: NSAccessibilityNotificationName

This notification is posted after an accessibility element’s title changes. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let uiElementDestroyed: NSAccessibilityNotificationName

This notification is posted after an accessibility element is destroyed. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let unitsChanged: NSAccessibilityNotificationName

This notification is posted after the units in a layout area change. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let valueChanged: NSAccessibilityNotificationName

This notification is posted after an accessibility element’s value changes. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let windowCreated: NSAccessibilityNotificationName

This notification is posted after a new window appears. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let windowDeminiaturized: NSAccessibilityNotificationName

This notification is posted after a window is restored to full size from the Dock. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let windowMiniaturized: NSAccessibilityNotificationName

This notification is posted after a window is put in the Dock. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let windowMoved: NSAccessibilityNotificationName

This notification is posted after a window moves. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

static let windowResized: NSAccessibilityNotificationName

This notification is posted after a window’s size changes. Post this notification using the NSAccessibilityPostNotification(_:_:) function instead of an NSNotificationCenter instance.

Instance Methods

See Also

First Steps

protocol NSAccessibilityContainsTransientUI

A set of methods that support accessibility in a UI that changes dynamically—usually in response to mouse-hover events.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software