title: SwiftUI - how to properly use func / struct in an app compared to Swift?
body: <p>I am still totally new to the whole SwiftUI concept and I find it quite difficult compared to other (or lets call them older) programing styles. I know this might sound silly, but I still don't grasp the concept of how to use functions. In most tutorials they use lots of structs and computed properties and apparently not many functions (but why?). I can design nice looking apps though and SwiftUI is so simply compared to normal Swift / UIKit, but I don't understand how to fill my apps with meaningful code so that they actually do something.</p>
  <p>Okay here is some example code with a function. Is this the right way to do this or should I use structs or something else?</p>
  <p>This code lets the user enter a number, and when the button is pressed &quot;5&quot; is added to the number and the result is shown above the TextField. Nothing special, but my question is would one use a function like this or is there a better way to do this with SwiftUI?</p>
  <pre><code>struct ContentView: View {
      @State private var result: String = &quot;0&quot;
      @State private var number: String = &quot;&quot;
      
      var body: some View {
          VStack(alignment: .leading) {
              Text(&quot;Result:&quot;)
                  .font(.title)
                  .fontWeight(.bold)
              Text(String(result)).padding()
              Text(&quot;Enter a number:&quot;)
                  .font(.title)
                  .fontWeight(.bold)
              TextField(&quot;Enter a number&quot;, text: $number)
                  .textFieldStyle(RoundedBorderTextFieldStyle())
                  .keyboardType(.numberPad)
              Button(&quot;Add 5&quot;) {
                  result = AddFive()
              }
                  .frame(minWidth: 0, maxWidth: .infinity)
                  .padding()
                  .foregroundColor(.white)
                  .background(Color.red)
                  .cornerRadius(40)
                  .padding(.horizontal, 20)
          }
          .padding()
      
      }
      
      func AddFive() -&gt; String {
          let num = Int(number) ?? 0
          let result = num + 5
          return String(result)
      }
      
  }
  </code></pre>
  <p>Of course I could use a computed property in this case, but I am thinking about much more complex code. In Swift I just pilled one function on top of the other.</p>