> ## Content Index
> Fetch the complete content index at: https://developerinsider.co/llms.txt
> Use this file to discover other available public pages before exploring further.

# Execute async/await method from Swift Command Line (CLI) Application
- URL: https://developerinsider.co/execute-async-await-method-from-swift-command-line-cli-application/
- Published: 2023-09-16T09:16:02.000Z
- Updated: 2023-10-17T04:53:22.000Z
- Description: Call an async/await function (with or without throws) from the Swift Command Line Application using the spacial @main attribute to prevent the CLI application from exiting before the asynchronous operation completes.
- Author: Vineet Choudhary
- Tags: Swift, Async, Await, Swift CLI

If you are writing a Swift CLI application and want to use asynchronous tasks, then you can use a special Swift attribute called `@main`. This is the inbuilt way to handle asynchronous operations and also prevents the Command Line Application/Tool from exiting before the asynchronous operation completes. Here's how you do it:

## 1\. Rename main.swift to AppName.swift

First of all, you need to rename the `main.swift` file to `AppName.swift`. For example, if your app name is AppBoxCLI then rename `main.swift` to `AppBoxCLI.swift`.

## 2\. Create a struct with the @main attribute

Now create a new `AppName` struct in `AppName.swift` file with the `@main` attribute. For example:

```swift
@main
struct AppBoxCLI {
	
}

```

## 3\. Add the main function with async

Now in the `AppName` struct, you need to add a main function with `async`. You can also add `throws` if you need to handle errors here. For example:

```swift
@main
struct AppBoxCLI {
  static func main() async throws {
    let appBoxCore = AppBoxCore.init()
    try await appBoxCore.upload()
  }
}

```