NEW: Learn to build the incredible iOS 15 Weather app today! >>

SOLVED: whether this is a trailing closure?

Forums > 100 Days of Swift

in apple swiftui tutorials code

struct LandmarkList: View {
    var body: some View {
        NavigationView {
            List(landmarks) { landmark in
                NavigationLink {
                } label: {
                    LandmarkRow(landmark: landmark)

I confuse with NavigationLink. parameter is two closures.but it is not a standard trailing closure

If the last parameter to a function is a closure, Swift lets you use special syntax called trailing closure syntax. Rather than pass in your closure as a parameter, you pass it directly after the function inside braces.

those code also work,but I do not know why

import Cocoa

func TwoClosure( action1:()->String , action2:()->String ){
    print("action1 output:\(action1())");
    print("action2 output:\(action2())");

    "this is action1"
} action2:{
     "this is action2"

func AnotherClosure( action3:()->String , action4:()->String ,action5:()->String ){

} action4: {
} action5: {


Since Swift 5.3 (released in Sept 2020), we have been able to use multiple trailing closures. That's what you are seeing here.

From the docs:

If a function takes multiple closures, you omit the argument label for the first trailing closure and you label the remaining trailing closures.


I got it, Thank for you repley


Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS, you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.