Post

Replies

Boosts

Views

Created

How to dismiss a Sheet and open a NavigationLink in a new View?
I have a View with a search button in the toolbar. The search button presents a sheet to the user and when he clicks on a result I would like the sheet to be dismissed and a detailView to be opened rather than navigating to the detailView from inside the sheet. The dismiss part is easy, but how do I open the detailView in the NavigationStack relative to the original View that presented the Sheet?
1
0
406
Nov ’22
How to dismiss a Sheet and open a NavigationLink in a new View?
I have a View with a search button in the toolbar. The search button presents a sheet to the user and when he clicks on a result I would like the sheet to be dismissed and a detailView to be opened rather than navigating to the detailView from inside the sheet. The dismiss part is easy, but how do I open the detailView in the NavigationStack relative to the original View that presented the Sheet?
1
0
983
Nov ’22
Error: "'async' call in an autoclosure that does not support concurrency"
@StateObject private var vm = QuotesViewModelImpl(service: QuotesServiceImpl()) --> Error Here          var body: some View {         Group {             if vm.quotes.isEmpty {                 LoadingView(text: "Fetching Quotes")             } else {                 List {                     ForEach(vm.quotes, id: \.anime) { quote in                         QuoteView(quote: quote)                     }                 }             }         }         .task {             await vm.getRandomQuotes()         }     }     } Here is the ViewModel: final class QuotesViewModelImpl: QuotesViewModel {     @Published private(set) var quotes: [Quote] = []     private let service: QuotesService     init(service: QuotesService) async {         self.service = service     }     func getRandomQuotes() async {         do {             self.quotes = try await service.fetchRandomQuotes()         } catch {             print(error)         }     } }
1
0
2.1k
Oct ’22
How to get more information from the documentation?
Text("Hello")             .font(.headline) .fontWeight(.semibold)             .foregroundColor(.primary)             .onTapGesture {                 // Some code             } In this example, there is text and some modifiers. I'd like to know what other modifiers I can use with that specific view. and also what other options I have for each modifier like what other types of fonts there are. How can I get that information using Apple's documentation?
0
0
309
Mar ’22
swiftui may be missing as an ancestor of this view.
The canvas is giving me an error and the app crashed because of this error: Fatal error: No ObservableObject of type LocationsViewModel found. A View.environmentObject(_:) for LocationsViewModel may be missing as an ancestor of this view. Also this is the error from the canvas: SwiftUI App crashed due to missing environment of type: LocationsViewModel. to resolve this add .environmentObject(LocationsViewModel(...)) to the appropriate preview Of course that line of code is already there and that error only shows in this swift file alone. other files works peoperly @main struct SwiftUI_Map_AppApp: App {     @StateObject private var vm = LocationsViewModel()     var body: some Scene {         WindowGroup {             LocationsView()                 .environmentObject(vm) // Any child view will have access to this environment object         }     } } LocationsView:     @EnvironmentObject private var vm: LocationsViewModel     var body: some View {         ZStack {             // Content         }         .sheet(item: $vm.sheetLocation) { location in             LocationDetailView(location: location)         }     } } struct LocationsView_Previews: PreviewProvider {     static var previews: some View {         LocationsView()             .environmentObject(LocationsViewModel())     } } LocationDetailView:     @EnvironmentObject private var vm: LocationsViewModel     let location: Location     var body: some View {         ScrollView {             VStack {                 imageSection                     .shadow(color: Color.black.opacity(0.3), radius: 20, x: 0, y: 10)                 VStack(alignment: .leading, spacing: 16) {                     titleSction                     Divider()                     descriptionSction                     Divider()                     mapLayer                 }                 .frame(maxWidth: .infinity, alignment: .leading)                 .padding()             }         }         .ignoresSafeArea()         .background(.ultraThinMaterial)         .overlay(alignment: .leading) {             backButton         }     } } struct LocationDetailView_Previews: PreviewProvider {     static var previews: some View {         LocationDetailView(location: LocationsDataService.locations.first!)             .environmentObject(LocationsViewModel()) <- Error here // as if it's not even there     } } LocationsViewModel: class LocationsViewModel: ObservableObject {     init() {         let locations = LocationsDataService.locations         self.locations = locations         mapLocation = locations.first!     }
4
0
4.3k
Mar ’22
How to dismiss a Sheet and open a NavigationLink in a new View?
I have a View with a search button in the toolbar. The search button presents a sheet to the user and when he clicks on a result I would like the sheet to be dismissed and a detailView to be opened rather than navigating to the detailView from inside the sheet. The dismiss part is easy, but how do I open the detailView in the NavigationStack relative to the original View that presented the Sheet?
Replies
1
Boosts
0
Views
406
Activity
Nov ’22
How to dismiss a Sheet and open a NavigationLink in a new View?
I have a View with a search button in the toolbar. The search button presents a sheet to the user and when he clicks on a result I would like the sheet to be dismissed and a detailView to be opened rather than navigating to the detailView from inside the sheet. The dismiss part is easy, but how do I open the detailView in the NavigationStack relative to the original View that presented the Sheet?
Replies
1
Boosts
0
Views
983
Activity
Nov ’22
Error: "'async' call in an autoclosure that does not support concurrency"
@StateObject private var vm = QuotesViewModelImpl(service: QuotesServiceImpl()) --> Error Here          var body: some View {         Group {             if vm.quotes.isEmpty {                 LoadingView(text: "Fetching Quotes")             } else {                 List {                     ForEach(vm.quotes, id: \.anime) { quote in                         QuoteView(quote: quote)                     }                 }             }         }         .task {             await vm.getRandomQuotes()         }     }     } Here is the ViewModel: final class QuotesViewModelImpl: QuotesViewModel {     @Published private(set) var quotes: [Quote] = []     private let service: QuotesService     init(service: QuotesService) async {         self.service = service     }     func getRandomQuotes() async {         do {             self.quotes = try await service.fetchRandomQuotes()         } catch {             print(error)         }     } }
Replies
1
Boosts
0
Views
2.1k
Activity
Oct ’22
How to get more information from the documentation?
Text("Hello")             .font(.headline) .fontWeight(.semibold)             .foregroundColor(.primary)             .onTapGesture {                 // Some code             } In this example, there is text and some modifiers. I'd like to know what other modifiers I can use with that specific view. and also what other options I have for each modifier like what other types of fonts there are. How can I get that information using Apple's documentation?
Replies
0
Boosts
0
Views
309
Activity
Mar ’22
swiftui may be missing as an ancestor of this view.
The canvas is giving me an error and the app crashed because of this error: Fatal error: No ObservableObject of type LocationsViewModel found. A View.environmentObject(_:) for LocationsViewModel may be missing as an ancestor of this view. Also this is the error from the canvas: SwiftUI App crashed due to missing environment of type: LocationsViewModel. to resolve this add .environmentObject(LocationsViewModel(...)) to the appropriate preview Of course that line of code is already there and that error only shows in this swift file alone. other files works peoperly @main struct SwiftUI_Map_AppApp: App {     @StateObject private var vm = LocationsViewModel()     var body: some Scene {         WindowGroup {             LocationsView()                 .environmentObject(vm) // Any child view will have access to this environment object         }     } } LocationsView:     @EnvironmentObject private var vm: LocationsViewModel     var body: some View {         ZStack {             // Content         }         .sheet(item: $vm.sheetLocation) { location in             LocationDetailView(location: location)         }     } } struct LocationsView_Previews: PreviewProvider {     static var previews: some View {         LocationsView()             .environmentObject(LocationsViewModel())     } } LocationDetailView:     @EnvironmentObject private var vm: LocationsViewModel     let location: Location     var body: some View {         ScrollView {             VStack {                 imageSection                     .shadow(color: Color.black.opacity(0.3), radius: 20, x: 0, y: 10)                 VStack(alignment: .leading, spacing: 16) {                     titleSction                     Divider()                     descriptionSction                     Divider()                     mapLayer                 }                 .frame(maxWidth: .infinity, alignment: .leading)                 .padding()             }         }         .ignoresSafeArea()         .background(.ultraThinMaterial)         .overlay(alignment: .leading) {             backButton         }     } } struct LocationDetailView_Previews: PreviewProvider {     static var previews: some View {         LocationDetailView(location: LocationsDataService.locations.first!)             .environmentObject(LocationsViewModel()) <- Error here // as if it's not even there     } } LocationsViewModel: class LocationsViewModel: ObservableObject {     init() {         let locations = LocationsDataService.locations         self.locations = locations         mapLocation = locations.first!     }
Replies
4
Boosts
0
Views
4.3k
Activity
Mar ’22