UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

var body: some View { ! Function declares an opaque return type

Forums > 100 Days of SwiftUI

I hoped to work through the SwiftUI Tutorial....I got as

Reading text from the user with TextField

but now the above error is preventing build of the examples.

Please Help! Mike

3      

Could you please show code with what you are trying to return?

4      

Check you have not made a typo as this will call this error

3      

I tried various ways of putting in a return but I am new to Swift and could not hit on something the compiler would accept.

struct ContentView: View { @State private var checkAmount = "" @State private var numberOfPeople = 2 @State private var tipPercentage = 2 let tipPercentages = [10, 15, 20, 25, 0] var body: some View { !!!!!! Function declares an opaque return type but has no return statements in its body from which to infer... VStack { Text("") Text("") } Section { TextField("Amount", text: $checkAmount) }

    Section {
        Text("$\(checkAmount)")
      .keyboardType(.decimalPad)
    }

    }

}

3      

Sorry about the mess above. My formating seems to have got lost. Mike

3      

I copied your code into Xcode as it was not obvious from the formatting here.

    var body: some View {
//        !!!!!! Function declares an opaque return type but has no return statements in its body from which to infer...
        VStack {
            Text("")
            Text("")
        }  //      <------- remove the { and put it below where it's indicated

        Section {
            TextField("Amount", text: $checkAmount)

        }

        Section {
            Text("$\(checkAmount)")
                .keyboardType(.decimalPad)
        }
              //    <--------- put the } here. That way, the 2 Sections are within the VStack.
    }

The issue is that your body gives back several Views : first a VStack and then 2 Sections. Put the 2 sections within the VStack so that the body only has 1 single View (the VStack).

3      

Sorry about the mess above. My formating seems to have got lost. Mike

For future reference: If you fence your code with backticks ``` on the line before and line after, the forum will format it nicely, like in @Pbaboe's post.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.