<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/OpenURLAction/callAsFunction(_:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI13OpenURLActionV14callAsFunction_10completiony10Foundation3URLV_ySbctF"
  },
  "title" : "callAsFunction(_:completion:)"
}
-->

# callAsFunction(_:completion:)

Asynchronously opens a URL, following system conventions.

```
@MainActor @preconcurrency func callAsFunction(_ url: URL, completion: @escaping (Bool) -> Void)
```

## Parameters

`url`

The URL to open.

`completion`

A closure the method calls after determining if
it can open the URL, but possibly before fully opening the URL.
The closure takes a Boolean value that indicates whether the
method can open the URL.

## Discussion

Don’t call this method directly. SwiftUI calls it when you
call the [`OpenURLAction`](/documentation/SwiftUI/OpenURLAction) structure that you get from the
[`Environment`](/documentation/SwiftUI/Environment), using a URL and a completion handler as arguments:

```
struct OpenURLExample: View {
    @Environment(\.openURL) private var openURL

    var body: some View {
        Button {
            if let url = URL(string: "https://www.example.com") {
                // Implicitly calls openURL.callAsFunction(url) { ... }
                openURL(url) { accepted in
                    print(accepted ? "Success" : "Failure")
                }
            }
        } label: {
            Label("Get Help", systemImage: "person.fill.questionmark")
        }
    }
}
```

For information about how Swift uses the `callAsFunction()` method to
simplify call site syntax, see
[Methods with Special Names](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID622)
in *The Swift Programming Language*.

---

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)