SwiftUI ViewModifier not working as a NavigationLink
The modifier doesn't work because the content
argument is not the actual view being modified, but instead is a proxy:
content is a proxy for the view that will have the modifier represented by Self applied to it.
Reference.
This is what a quick debugging over the modifier shows:
(lldb) po content
SwiftUI._ViewModifier_Content<SwiftUIApp.NavLink>()
As the proxy is an internal type of SwiftUI, we can't know for sure why NavigationLink
doesn't work with it.
A workaround would be to skip the modifier, and only add the extension over View
:
extension View {
func navLink(title: String) -> some View {
NavigationLink(destination: content) {
Text(title)
}
}
}
SwiftUI detect edit mode
It is on same level so environment is not visible, because it is activated for sub-views.
A possible solution is to separate dependent part into standalone view, like
Form {
InternalView()
}
.toolbar {
EditButton()
}
Tested with Xcode 13.4 / iOS 15.5
Test module on GitHub
SwiftUI Map causes modifying state during view update
Seems to me it's a bug in Map
(as of Xcode Version 13.3.1 (13E500a) and iPhone 13 Simulator). If you switch to the Breakpoints side-bar and click the + and add an All Runtime Issues breakpoint, if you debug and click the button you'll hit the breakpoint and see this:
This trace shows that when the button is tapped to change the tracking state, SwiftUI updates MKMapView
with the new state by calling _setUserTrackingMode
(line 13) but a side effect of this is a callback to mapLayerDidChangeVisibleRegion
(line 9) and it tries to set the value of a Binding (line 6), most likely the coordinateRegion
. It shouldn't be setting a Binding while it is updating the MKMapView from the State, which is what results in the warning. We should all report the bug - I submitted it as FB9990674 under Developer Tools - SwiftUI, feel free to reference my number.
Related Topics
Drag Rotate a Node Around a Fixed Point
Xcode Beta 6 "Type of Expression Is Ambiguous Without More Context" Navigationlink
Scncamera Limit Arcball Rotation
Draw a Hole in a Rectangle with Spritekit
How to Create a String from Utf8 in Swift
How to Write Inline Assembly in Swift
Programmatically Creating Constraints Bound to View Controller Margins
Swift Arrays and Contains, How to Determine If a Collection Contains an Object or Value
How to Print a String from Plist Without "Optional"
How Is Optional Binding Used in Swift
How to Implement Copy Constructor in Swift Subclass
What Determines Whether a Swift 5.5 Task Initializer Runs on the Main Thread
Swift 4 Decode Simple Root Level JSON Value
Pass C Function Callback in Swift
Reference as Key in Swift Dictionary