liveview-native / liveview-client-swiftui

MIT License
349 stars 29 forks source link

tabItem modifier doesn't conform entirely to Apple documentation #1365

Closed bcardarella closed 1 month ago

bcardarella commented 1 month ago
tabItem(:mylabel)

works but from the Apple documentation:

func tabItem<V>(@ViewBuilder _ label: () -> V) -> some View where V : View

I presume that the _ default named argument's name is label so if I try:

tabItem(label: :mylabel)

the modifier doesn't match in the client:

Stylesheet parsing failed for modifier `tabItem` in class `tabItem(content: :tablabel)`:

  |
1 | tabItem(content: :tablabel)
  | ^ No matching clause found for modifier `tabItem`. Expected `tabItem(_:)`

in  (home_live.swiftui.neex:1)
carson-katri commented 1 month ago

_ means the argument has no label. So in SwiftUI you write this as:

tabItem({ Text("Label") })

but this would cause an error:

tabItem(label: { Text("Label") })
// error: Extraneous argument label 'label:' in call
bcardarella commented 1 month ago

yes I saw that error and looked at the Swift source, my question is if label is a supported named argument in the original SwiftUI, I see it in the Apple docs or am I misunderstanding.

carson-katri commented 1 month ago

I think you're misunderstanding the function signature. In that example, the argument label is _, with the second label being label (for use within the function body).

When the first argument label is a wildcard _ character, you cannot pass a label.

func myFunction(_ unlabeled: Any) -> Any {
  // use `unlabeled` in here
}

// call without a labeled argument.
myFunction(5)
myFunction(unlabeled: 5) // this form is invalid

A wildcard argument label does not mean the label is optional, it means the label cannot be used at the call site at all.

bcardarella commented 1 month ago

ah ok, it's not a named argument. That makes sense