Instance Method インスタンスメソッド

callAsFunction()

Initiates a refresh action.

Declaration 宣言

func callAsFunction() async

Discussion 議論

Don’t call this method directly. SwiftUI calls it when you call the RefreshAction structure that you get from the Environment:


struct RefreshableView: View {
    @Environment(\.refresh) private var refresh


    var body: some View {
        Button("Refresh") {
            Task {
                await refresh?()  // Implicitly calls refresh.callAsFunction()
            }
        }
        .disabled(refresh == nil)
    }
}

For information about how Swift uses the callAsFunction() method to simplify call site syntax, see Methods with Special Names in The Swift Programming Language. For information about asynchronous operations in Swift, see Concurrency.