Post

Replies

Boosts

Views

Activity

Reply to Too many entries for NavigationStack
The issue you're facing where the app crashes after adding more than 16 NavigationLinks to a NavigationStack is likely related to a SwiftUI limitation known as the "10-View Limit." SwiftUI imposes a limit on the number of NavigationLink views that can be placed in a single navigation stack, which is usually around 10 to 16, depending on the device and iOS version. To work around this limitation, you can consider organizing your medication list differently. Instead of creating a separate view for each medication and using NavigationLinks, you can create a dynamic list of medications using a ForEach loop and then pass the selected medication to a detail view when tapped. Here's an example of how you can do that: struct Medication: Identifiable { let id = UUID() let name: String // Add any other properties you need for each medication } struct Medikamente: View { let medications: [Medication] = [ Medication(name: "Acetylsalicylsäure"), Medication(name: "Amiodaron"), Medication(name: "Atropin"), // Add more medications here ] @State private var selectedMedication: Medication? = nil var body: some View { NavigationView { List(medications) { medication in Button(action: { selectedMedication = medication }) { Text(medication.name) } } .sheet(item: $selectedMedication) { medication in MedicationDetailView(medication: medication) } .navigationTitle("Medikamente") } } } struct MedicationDetailView: View { let medication: Medication var body: some View { // Create a detailed view for the selected medication Text("Details for \(medication.name)") // Add more content as needed } } In this example, we create a list of medications using a ForEach loop and use a @State variable to track the selected medication. When a medication is tapped, we display a detail view for that medication using the .sheet modifier. This approach should allow you to display a list of medications without hitting the limitation imposed by SwiftUI's NavigationLink behavior.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to Allowing taps only in vstack deep links within a HStack in widget
In iOS 14 and later, widgets are interactive by default, which means users can tap on any part of the widget to launch the associated app or perform some action. However, if you want to make certain parts of the widget non-tappable, you can use the .background(_:) modifier with a clear color to disable hit testing on those areas. Here's how you can modify your code to make only the VStacks within the HStack tappable: struct ThreeContactWidgetView: View { var entry: Provider.Entry var body: some View { HStack(spacing: 12) { Spacer() ForEach(contacts.prefix(3)) { contact in Link(destination: URL(string: "myApp://call?contactId=\(contact.identifier)")!) { VStack { Image(systemName: "person.crop.circle.fill") .resizable() .aspectRatio(contentMode: .fit) .clipShape(Circle()) Text("\((contact.givenName))") .font(.headline) .padding(.top, 4) } .frame(width: 100) } .background(Color.clear) // Disable hit testing on this area } Spacer() } .padding() .containerBackground(for: .widget) {} } } By adding .background(Color.clear) to each Link's VStack, you should prevent tap gestures from being recognized on the Spacer areas and only allow taps on the VStacks, which will trigger the associated deep links for the respective contacts.
Topic: App & System Services SubTopic: General Tags:
Oct ’23
Reply to SwiftUI and @FetchRequest - modify predicate or sort dynamically?
After two years I have the solution you are looking for, but you probably don't need it anymore, but for others who may also be wondering the same thing here is an example of how to sort a FetchedResults type with a search bar You'll ned to include this at the top of your struct. and you have to change "Item" to the name of the entity in your core data file. @FetchRequest(sortDescriptors: []) var items: FetchedResults<Item> @State private var searchingFor = "" And link this to the end of your list or whatever contains your list. You'll have to change title to whatever the name of your attribute is in your core data file .searchable(text: $searchingFor, placement: .navigationBarDrawer(displayMode: .always), prompt: "Search Titles") .onChange(of: searchingFor){ value in if (searchingFor != ""){ items.nsPredicate=NSPredicate(format: "title CONTAINS[c] %@", searchingFor) } else { items.nsPredicate=nil } Let me know if you have any questions!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
Reply to Too many entries for NavigationStack
The issue you're facing where the app crashes after adding more than 16 NavigationLinks to a NavigationStack is likely related to a SwiftUI limitation known as the "10-View Limit." SwiftUI imposes a limit on the number of NavigationLink views that can be placed in a single navigation stack, which is usually around 10 to 16, depending on the device and iOS version. To work around this limitation, you can consider organizing your medication list differently. Instead of creating a separate view for each medication and using NavigationLinks, you can create a dynamic list of medications using a ForEach loop and then pass the selected medication to a detail view when tapped. Here's an example of how you can do that: struct Medication: Identifiable { let id = UUID() let name: String // Add any other properties you need for each medication } struct Medikamente: View { let medications: [Medication] = [ Medication(name: "Acetylsalicylsäure"), Medication(name: "Amiodaron"), Medication(name: "Atropin"), // Add more medications here ] @State private var selectedMedication: Medication? = nil var body: some View { NavigationView { List(medications) { medication in Button(action: { selectedMedication = medication }) { Text(medication.name) } } .sheet(item: $selectedMedication) { medication in MedicationDetailView(medication: medication) } .navigationTitle("Medikamente") } } } struct MedicationDetailView: View { let medication: Medication var body: some View { // Create a detailed view for the selected medication Text("Details for \(medication.name)") // Add more content as needed } } In this example, we create a list of medications using a ForEach loop and use a @State variable to track the selected medication. When a medication is tapped, we display a detail view for that medication using the .sheet modifier. This approach should allow you to display a list of medications without hitting the limitation imposed by SwiftUI's NavigationLink behavior.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to Allowing taps only in vstack deep links within a HStack in widget
In iOS 14 and later, widgets are interactive by default, which means users can tap on any part of the widget to launch the associated app or perform some action. However, if you want to make certain parts of the widget non-tappable, you can use the .background(_:) modifier with a clear color to disable hit testing on those areas. Here's how you can modify your code to make only the VStacks within the HStack tappable: struct ThreeContactWidgetView: View { var entry: Provider.Entry var body: some View { HStack(spacing: 12) { Spacer() ForEach(contacts.prefix(3)) { contact in Link(destination: URL(string: "myApp://call?contactId=\(contact.identifier)")!) { VStack { Image(systemName: "person.crop.circle.fill") .resizable() .aspectRatio(contentMode: .fit) .clipShape(Circle()) Text("\((contact.givenName))") .font(.headline) .padding(.top, 4) } .frame(width: 100) } .background(Color.clear) // Disable hit testing on this area } Spacer() } .padding() .containerBackground(for: .widget) {} } } By adding .background(Color.clear) to each Link's VStack, you should prevent tap gestures from being recognized on the Spacer areas and only allow taps on the VStacks, which will trigger the associated deep links for the respective contacts.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to Save Image in Core Data. Please Help!
how do you import UIKit into your core data properties file? my file won't let me add or remove anything @Jineshsethia
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jul ’22
Reply to Broken Date List
This seems to only be an issue in the simulator. When ran on an actual device it works as intended. Really odd.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Sheet Won't Display in a ContextMenu
Fixed with overcomplicated work around :P
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to TestFlight emails in Spam. Any possible solution?
I’m curious about this as well as I will be launching my app on TestFlight soon.
Replies
Boosts
Views
Activity
Jun ’22
Reply to SwiftUI and @FetchRequest - modify predicate or sort dynamically?
After two years I have the solution you are looking for, but you probably don't need it anymore, but for others who may also be wondering the same thing here is an example of how to sort a FetchedResults type with a search bar You'll ned to include this at the top of your struct. and you have to change "Item" to the name of the entity in your core data file. @FetchRequest(sortDescriptors: []) var items: FetchedResults<Item> @State private var searchingFor = "" And link this to the end of your list or whatever contains your list. You'll have to change title to whatever the name of your attribute is in your core data file .searchable(text: $searchingFor, placement: .navigationBarDrawer(displayMode: .always), prompt: "Search Titles") .onChange(of: searchingFor){ value in if (searchingFor != ""){ items.nsPredicate=NSPredicate(format: "title CONTAINS[c] %@", searchingFor) } else { items.nsPredicate=nil } Let me know if you have any questions!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Passing a reference between views
I think it’s called a pointer
Replies
Boosts
Views
Activity
Jun ’22
Reply to Dismissing a Sheet That Doesn't Call Another View
Nevermind. I just need to toggle isSheetShowing again
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Optional Type Date
I want date to be nil if no date is selected. How do I do that in the DatePicker?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Embed SwiftUI View in UITabBarController
Just use TabView in App file and put your views in there
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to NSPersistentCloudKitContainer: Exclude Relationship From Share
I would also like this information as I’m not sure my idea would work, but try this and get back to me if you find a way to do this. Create a func in your persistence file that removes relationships from your entity and then executes the share(_:to:completion:).
Replies
Boosts
Views
Activity
Jun ’22
Reply to iOS 16 Beta
You have to go to the VPN & Device Management and it should be the bottom one.
Topic: Community SubTopic: Apple Developers Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to How do I Test apps for developers? Using test flight
To use TestFlight you have to join the Apple developer team ($98.99 annually). To do this download the developer app and go to account and it should give an option to sign up there.
Replies
Boosts
Views
Activity
Jun ’22
Reply to Unknown Errors From Inverse Relationship. Please Help!!!
I think it has something to do with the relationship part because just making a plain entity in the data model isn't a problem. Is there something more you have to do for the relationship?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22