Итак, протокол не поддерживает some View
в качестве возвращаемого типа ... Я пробую это:
public extension View {
func popSheet(isPresented: Binding<Bool>, arrowEdge: Edge = .bottom, content: @escaping () -> PopSheet) -> some View {
Group {
if UIDevice.current.userInterfaceIdiom == .pad {
popover(isPresented: isPresented, attachmentAnchor: .rect(.bounds), arrowEdge: arrowEdge, content: {
content().popover()
})
} else {
actionSheet(isPresented: isPresented, content: {
content().actionSheet()
})
}
}
}
}
protocol PopSheet {
func actionSheet() -> ActionSheet
associatedtype View
func popover() -> View
}
Но не удается полностью объявить функцию, а также ошибки content().popover()
.
Method must be declared internal because its parameter uses an internal type
Protocol 'PopSheet' can only be used as a generic constraint because it has Self or associated type requirements
Member 'popover' cannot be used on value of protocol type 'PopSheet'; use a generic constraint instead