<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSSelectorFromString(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@F@NSSelectorFromString"
  },
  "title" : "NSSelectorFromString(_:)"
}
-->

# NSSelectorFromString(_:)

Returns the selector with a given name.

```
func NSSelectorFromString(_ aSelectorName: String) -> Selector
```

## Parameters

`aSelectorName`

A string of any length, with any characters, that represents the name of a selector.

## Return Value

The selector named by `aSelectorName`. If `aSelectorName` is `nil`, or cannot be converted to UTF-8 (this should be only due to insufficient memory), returns `(SEL)0`.

## Discussion

To make a selector, [`NSSelectorFromString(_:)`](/documentation/Foundation/NSSelectorFromString(_:)) passes a UTF-8 encoded character representation of `aSelectorName` to <doc://com.apple.documentation/documentation/ObjectiveC/sel_registerName(_:)> and returns the value returned by that function. Note, therefore, that if the selector does not exist it is registered and the newly-registered selector is returned.

Recall that a colon (”:”) is part of a method name; `setHeight` is not the same as `setHeight:`.

---

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)