---
title: execute()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/nsscriptcommand/execute()
---

# execute()

Executes the command if it is valid and returns the result, if any.

## Declaration

```swift
func execute() -> Any?
```

## Discussion

Discussion Before this method executes the command (through NSInvocation mechanisms), it evaluates all object specifiers involved in the command, validates that the receivers can actually handle the command, and verifies that the types of any arguments that were initially object specifiers are valid. You shouldn’t have to override this method. If the command’s receivers want to handle the command themselves, this method invokes their defined handler. Otherwise, it invokes performDefaultImplementation().

## See Also

### Related Documentation

- [evaluatedReceivers](foundation/nsscriptcommand/evaluatedreceivers.md)
- [evaluatedArguments](foundation/nsscriptcommand/evaluatedarguments.md)

### Executing the command

- [performDefaultImplementation()](foundation/nsscriptcommand/performdefaultimplementation().md)
