Swiftui function Calls

Hello, I can’t seem to call this function anywhere in my code. I get this error: Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type when I place it like this:

var body: some View {
        VStack {
            MapView(myValue: myValue)

func findLocations() {
        let myCount = myLocations.count
        // if myCount <= 1 {return mapView}
        for myLocation in myLocations {
            if (myLocation.date! >= WeeklySpan(increment: myValue) && myCount >= 1 ){
                coordArray.append([myLocation.latitude, myLocation.longitude])

Hi @flmcl,
if the code you have above is exactly as you have in your ide,
then you need to add a return before the VStack to make it work

In the code block

   var body: some View {
        VStack { ... }

you need to return something that is a View and that something in your case is VStack however before that you are also calling a function. Return is automatically added if it was just VStack, now that you have added the function call, you need to manually add the return.

   var body: some View {
        return VStack { ... }


1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.