7
votes

I have a problem with SwiftUI. I am creating a list with a navigation bar, and I want to set navigation bar mode to inline, I don't want it to be large which is by default. But when I set navigation bar title mode to inline, the app crashes.

struct User {
    var index: Int
    var name: String
}

struct ContentView : View {
    var users: [User] = [
        User(index: 0, name: "Peter"),
        User(index: 1, name: "Marko"),
        User(index: 2, name: "John")]

    var body: some View {
        NavigationView {
            List(users.identified(by: \.index)) {
                UserRow(user: $0)
            }
            .navigationBarTitle(Text("Users"), displayMode: .inline)
        }
    }
}

struct UserRow: View {
    var user: User
    var body: some View {
        Text(user.name)
    }
}

I suppose that it is a SwiftUI bug.

Does someone know what could be the problem? Thanks in advance.

1
The above code is working fine. perhaps some other issues might affect a crash. Which XCode Beta version you use?Ketan Odedra
I've tried with beta 1 and the latest beta 4. It crashes all the time. Maybe the problem is because I'm testing on simulator. The app crashes in line: window.makeKeyAndVisible() I get the error: "nw_endpoint_get_type called with null endpoint ... __nwlog_err_simulate_crash simulate crash already simulated nw_endpoint_get_type called with null endpoint ..." Some other people also have reported similar problem: forums.developer.apple.com/thread/120104Vladimir88dev
This still happens even after XCode 11 was officially released. Not sure if it would work on a barebones SwiftUI-app, but our case does not where we have UIHostingController wrapping the SwiftUI view(s).Simon
I have the same problem since I added UINavigationBar.appearance().isTranslucent = falseuser12504463
Seem like Swift UI bug, UINavigationBar.appearance().isTranslucent = false , navigationBarTitle - displayMode: .inline and .navigationViewStyle(StackNavigationViewStyle()) combination made crash for me. I gonna remove UINavigationBar.appearance().isTranslucent = false for now to solveThein

1 Answers

0
votes

Looks like it is fixed in Xcode 11.4 beta 2