If not too long, it is easier to Paste And Match Style for the code. You get line numbers directly.
Code Block import SwiftUI |
import SDWebImage |
import HalfModal |
import Foundation |
|
struct rocketView: View { |
|
@State var rockets: [Rocket] = [] |
@State private var showingHalfModal2: Bool = false |
|
var body: some View { |
ZStack { |
NavigationView { |
VStack { |
Spacer() |
.frame(height: 1) |
.navigationBarTitle("Rockets") |
|
List { |
|
ForEach(rockets, id: \.id) { rocket in |
|
Button(action: { |
withAnimation { |
self.showingHalfModal2 = true |
} |
}) { |
rHStack(rocket) |
} |
.buttonStyle(PlainButtonStyle()) |
} |
} |
}.onAppear { |
rocketApiCall().getUsers{ (rockets) in rockets = rockets} |
}.listStyle(SidebarListStyle()) |
.frame(alignment: .center) |
} |
} |
if showingHalfModal2 { |
HalfModalView(content: AnyView(HStack { |
VStack { |
Text("test123") |
.padding() |
} |
}), header: AnyView(HStack { |
VStack(alignment: .leading) { |
Text("test") |
Text("test") |
.font(.system(size: 10)) |
.foregroundColor(Color.gray) |
}}), isPresented: $showingHalfModal2) |
} |
} |
|
func rHStack(_ rocket: Rocket) -> some View { |
HStack { |
|
Group { |
Text(rocket.name) |
.font(.system(size: 23)) |
.frame(maxWidth: .infinity, alignment: .leading) |
.fixedSize(horizontal: false, vertical: true) |
Text("Active: " + String(rocket.active)) |
.font(.system(size: 15)) |
.foregroundColor(Color.gray) |
Spacer() |
} |
} |
} |
} |
|
struct rocketView_Previews: PreviewProvider { |
static var previews: some View { |
rocketView() |
} |
} |
I have moved quite a chunk of code to a new Swift file called rocketView, it got rid of the original error, but now I get the error Cannot convert value of type '(inout [Rocket]) -> ()' to expected argument type '([Rocket]) -> ()' on line 45... my code is attached. (Line 45 is the line between }.onAppear { and }.listStyle...
So the error is now line 34.
But you don't show the code for
rocketApiCall() and its getUsers
So it's hard to say.
Note: it is more readable to give a different name anyway, such as:
rocketApiCall().getUsers { (theRockets) in rockets = theRockets}
Try also removing the parenthesis around theRockets