---
title: "NSSelectorFromString(_:)"
framework: foundation
role: symbol
role_heading: Function
path: "foundation/nsselectorfromstring(_:)"
---

# NSSelectorFromString(_:)

Returns the selector with a given name.

## Declaration

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

## Parameters

- `aSelectorName`: A string of any length, with any characters, that represents the name of a selector.

## Return Value

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

Discussion To make a selector, NSSelectorFromString(_:) passes a UTF-8 encoded character representation of aSelectorName to 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:.

## See Also

### Type Lookup

- [NSClassFromString(_:)](foundation/nsclassfromstring(_:).md)
- [NSStringFromClass(_:)](foundation/nsstringfromclass(_:).md)
- [NSStringFromSelector(_:)](foundation/nsstringfromselector(_:).md)
- [NSStringFromProtocol(_:)](foundation/nsstringfromprotocol(_:).md)
- [NSProtocolFromString(_:)](foundation/nsprotocolfromstring(_:).md)
