SwiftUI: Disable translucence in NavigationView - swiftui

I'm working on rewriting an app to SwiftUI. Currently I'm struggling with what seems an easy one: Disabling the translucence in NavigationView.
The code I used before is:
UINavigationBar.appearance().isTranslucent = false
But isTranslucent is not in the autocomplete suggestions.
If I put it anyway, the app crashes inside the ViewRendererHost.render(interval:updateDisplayList:) :
Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1c34016a0)
Did I miss something? How can I disable the translucence of NavigationView in SwiftUI?
Thank you for your suggestions!

This is a bug, and you will instead have to continue using UINavigationController. You can still have all your content as SwiftUI in UIHostingControllers, but you will have to keep the UIKit navigation stack or it'll explode.

Related

how to make swiftUI buttons exclusive?

using swiftUI i have a lot of Buttons which i need to make only one can be clicked at the same time.
By default in swiftUI you have two or more buttons on a view you can click them all at once
I tried adding the following:
UIButton.appearance().isMultipleTouchEnabled = false
UIButton.appearance().isExclusiveTouch = true
With UIKit we had exclusiveTouch and MultiTouchEnabled but how do we do this with swiftUI?
What is the correct way to solve this application wide?
Update: The use case is simple there is a view with a login button and a register button and now the user can tap both at the same time which i don't want

SwiftUI - Adding Toolbar to Keyboard not working with XCode 13.2

I'm a newbie developer. Based on what I've read, in the latest version of Xcode it is possible to add a toolbar item to the keyboard in a straightforward manner:
TextField("Today's weight", text: $weight)
.textFieldStyle(.roundedBorder)
.keyboardType(.decimalPad)
.toolbar {
ToolbarItem(placement: .keyboard) {
Button("Click") {
isKeyBoardActive = false
}
}
}
The app is designed with TabView for navigation rather than a navigation view.
Based on this link I assumed that Xcode 13.1 would require a navigation view for this to work, but Xcode 13.2 would not. I've confirmed that my Xcode version is 13.2.1.
I've also tried the code with 'ToolbarItem' and 'ToolbarItemGroup'. When my app is run, no toolbar appears with either variation.
Any help would be greatly appreciated.
Edit: Upon further troubleshooting, I've realised that embedding the TextField in the TabView causes it not to work. If its a standalone view (i.e. not in a TabView) the toolbar item is added as expected. Extracting the TextField to its own subview while within TabView doesn't seem to work either.

How to query UITextField wrapped in UIViewRepresentable from a Xcode UI test?

I'm developing my app with SwiftUI, but some elements are still from the UIKit world, e.g. one UITextField with special behavior, that's why I use a UIViewRepresentable where the makeUIView methods returns a UITextField.
When I try to enter text via UI test, I don't succeed in querying the textfield; even app.textFields doesn't return anything.
Is this because of using UIViewRepresentable, am I missing something?
I had the same situation you described. Make sure to set accessibilityIdentifier in makeUIView. Also bear in mind that if you're setting isSecureTextEntry to true, you should access it using app.secureTextFields

How to avoid app crash with TabView inside NavigationView when navigate backwards ios 13 SwiftUI

I'm using a TabView inside NavigationView but my app crashes when I try to navigate backwards, it shows this error message "Thread 1: EXC_BAD_ACCESS (code=2, address=0x16ad5bff0)" at AppDelegate class. In ios 14 device it works fine but it crashes on ios 13. I think this is navigationView issue in ios 13. I'm looking for an alternative in iOS 13 and avoid the crash.
PS: I'm using xcode 12.
Nesting TabView's inside of NavigationView's has been an issue since SwiftUI started. The cleanest workaround to this is to create view "View layers". Take a look this answer to give you an idea about how they work.
Pure SwiftUI login, signup, register flow, is it possible?
There is a lot that you can do with layering in SwiftUI that feels natural. Check it out and let me know if you have any questions!

Bug_Detected_In_Client_Of_UITableView_Invalid_Number_Of_Rows_In_Section Crash in SwiftUI

I am running iOS 14.0.1, Xcode 12.0.1 targeting iOS14.
I have data in CoreData that I pull out and display in a SwiftUI List/ForEach. It was working fine on iOS13, but when I went to iOS14 is started getting intermittent crashes. After I add a new object to core data and then go back to the List/ForEach view it repaints the list but sometimes it over counts the number of elements and crashes with a Bug_Detected_In_Client_Of_UITableView_Invalid_Number_Of_Rows_In_Section. Since the array of entities from Core Data is observable and mapped directly to the List/ForEach I have no control over the count at all. It never crashes on the iOS 14 simulator, only on a real iPhone. It does not crash ever time I add a new entry, only sometimes seemly at random. It never crashed on iOS13 either on the simulator or a real iPhone.
This is the code to display the list;
List {
ForEach(self.locations, id: \.self) { location in
LocationView(currentLocation: location)
}
.onDelete(perform: self.deleteSelectedRow)
}
Is anyone else having this issue? It appears to be some internal bug to iOS14 ForEach processing with a CoreData created observable object, but if that were true I would think many people would be having the same issue, but I do not see any comments about this some sort of problem. Anyone have any ideas?
Thanks in advance for any an all ideas and help anyone can give!
the crash is due to the underlying TableView code inside SwiftUI framework.
Refer to this link for more info: https://developer.apple.com/forums/thread/129956?page=1#650267022