Это код, вызывающий ошибку в заголовке, он появляется в строке с var body: some View
import SwiftUI
import Contacts
import MapKit
extension Restaurant {
func openInMaps() {
let placemark = MKPlacemark(coordinate: location.coordinate, addressDictionary: [CNPostalAddressStreetKey as String: address!])
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = self.name
mapItem.phoneNumber = phone
let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
mapItem.openInMaps(launchOptions: launchOptions)
}
func openInGoogleMaps() {
if let url = URL(string: "comgooglemapsurl://maps.google.com/?q=\(restaurant.name.URLEncoded)@\(restaurant.location.coordinate.latitude),\(restaurant.location.coordinate.longitude)") {
UIApplication.shared.open(url, options: [:])
}
}
}
struct RestaurantView: View {
@State private var isSshowingMapActionSheet = false
@State private var isShowingSafariView = false
let restaurant: Restaurant!
var currenstatus: String {
return restaurant.isOpen ? "Öppet" : "Stängt"
}
lazy var mapActionSheetButtons: [ActionSheet.Button] = [
.default(Text("Öppna i Kartor"), action: {
self.restaurant.openInMaps()
}),
.default(Text("Öppna i Google Maps"), action: {
self.restaurant.openInGoogleMaps()
}),
.cancel(Text("Avbryt"))
]
lazy var mapActionSheet = ActionSheet(title: Text(""), buttons: mapActionSheetButtons)
init(_ restaurant: Restaurant) {
self.restaurant = restaurant
}
var body: some View {
List {
ListRow("ClockGlyph", action: {
}, label: {
OpenHoursView(restaurant)
})
ListRow("PhoneGlyph", action: {
UIApplication.shared.op
}, label: {
Text(self.restaurant!.phone)
})
if (restaurant.homepage != nil) {
return ListRow("SafariGlyph", action: {
isShowingSafariView.toggle()
}, label: {
Text(restaurant.homepage)
})
} // End of if
ListRow("PhoneGlyph", action: {
UIApplication.shared.canOpenURL(self.restaurant.phoneURL)
}, label: {
Text(self.restaurant.phone)
})
if restaurant!.facebookURL != nil {
ListRow("FacebookGlyph", action: {
}, label: {
Text(self.restaurant.facebookURL!)
})
}
ListRow("PinGlyph", action: {
self.isSshowingMapActionSheet.toggle()
}, label: {
VStack {
Text(restaurant!.address!.replacingOccurrences(of: "\n", with: ", "))
Text("Visa vägbeskrivning")
.font(.subheadline)
.foregroundColor(.gray)
}
})
.actionSheet(isPresented: $isSshowingMapActionSheet, content: {
mapActionSheet
})
.sheet(item: $isShowingSafariView, content: {
SafariView(url: restaurant.homepageURL)
})
} // End of List
} // End of body
} // End of RestaurantView
struct RestaurantView_Previews: PreviewProvider {
static var previews: some View {
RestaurantView(Restaurant.allRestaurants.first!)
}
}
И это мой класс ListRow:
struct ListRow<Label> : View where Label : View {
let image: Image
var action:(() -> ())
let label: () -> Label
init(_ image: Image, action: @escaping () -> Void, @ViewBuilder label: @escaping () -> Label) {
self.image = image
self.action = action
self.label = label
}
var body: some View {
Button(action: self.action) {
HStack(spacing: 10) {
image.resizable().frame(width: 20, height: 20)
self.label().font(.subheadline)
}
}
}
}
Спасибо в заранее!