This is my code:
i
import SwiftUI
struct RestaurantView: View {
@State private var isSshowingMapActionSheet = false
@State private var isShowingSafariView = false
let restaurant: Restaurant!
var currenstatus: String {
return restaurant.isOpen ? "Open" : "Closed"
}
let mapActionSheetButtons: [ActionSheet.Button] = [
.default(Text("Öppna i Kartor"), action: {
self.restaurant.openInMaps() <-- ERROR OCCURS HERE
}),
.default(Text("Öppna i Google Maps"), action: {
self.restaurant.openInGoogleMaps() <-- AND HERE
}),
.cancel(Text("Avbryt"))
]
lazy var mapActionSheet = ActionSheet(title: Text(""), buttons: mapActionSheetButtons)
init(_ restaurant: Restaurant) {
self.restaurant = restaurant
}
var body: some View {
List {
ListRow(Image("ClockGlyph"), action: {
}, label: {
OpenHoursView(restaurant)
})
ListRow(Image("PhoneGlyph"), action: {
UIApplication.shared.op
}, label: {
Text(self.restaurant!.phone)
})
if (restaurant.homepage != nil) {
ListRow(Image("SafariGlyph"), action: {
self.isShowingSafariView.toggle()
}, label: {
Text(restaurant.homepage)
})
} // End of if
ListRow(Image("PhoneGlyph"), action: {
UIApplication.shared.canOpenURL(self.restaurant.phoneURL)
}, label: {
Text(self.restaurant.phone)
})
if restaurant!.facebookURL != nil {
ListRow(Image("FacebookGlyph"), action: {
}, label: {
Text(self.restaurant.facebookURL!)
})
}
ListRow(Image("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!)
}
}}