SwiftUI Tutorials Need Updating for PresentationButton in Beta 2

PresentationButton init has been altered for Xcode 11 Beta 2 to use a ViewBuilder - https://developer.apple.com/documentation/swiftui/presentationbutton/3326830-init?changes=latest_beta

Examples listed in SwiftUI Tutorials Need Updating

From: Working with UI Controls Tutorial


Home.swift - Beta 1 code

.navigationBarItems(trailing:

PresentationButton(

Image(systemName: "person.crop.circle")

.imageScale(.large)

.accessibility(label: Text("User Profile"))

.padding(),

destination: ProfileHost()

)

)


Home.swift - Beta 2 code

.navigationBarItems(trailing:

PresentationButton(

destination: ProfileHost(), label:

{ Image(systemName: "person.crop.circle")

.imageScale(.large)

.accessibility(label: Text("User Profile"))

.padding()

}

)

)

Replies

In Composing Complex Interfaces it should be: "destination: Text("User Profile"),"


  .navigationBarItems(trailing:
       PresentationButton(
            destination: Text("User Profile"),     
            label: { Image(systemName: "person.crop.circle")
                 .imageScale(.large)
                 .accessibility(label: Text("UserProfile"))
                 .padding()
            }
       )
  )


Took me 30 minutes to figure that one out 😝

Thank you midnight beep, This helped emensly. I am learning Swift at the same time as SwiftUI (30+ years of C/C++ and 20 years of Objecte-C background). For those in the same boat, this is an Auto Closure as referenced in "The Swift Programming Language Guide".

Oh duh, I had just started bashing my head against that one.. thanks Saved me a bit of time.