title: Calling function from view SwiftUI
body: <p>I'm trying to call a function from view using SwiftUI. This view receive an String parameter from view that is calling it.</p>
  <pre><code>struct BookList: View {
      var name: String
      var body: some View {
          let data: () = getData(from: self.name)
          ...
      }
  }
  </code></pre>
  <p>The function get data is consuming a rest service and getting some data.</p>
  <pre><code>func getData(from url: String){
      let task = URLSession.shared.dataTask(with: URL(string: url)!, completionHandler: { data, response, error in
          guard let data = data, error == nil else {
              print(&quot;Something went wrong&quot;)
              return
          }
          
          //Have data
          var result: Response?
          do {
              result = try JSONDecoder().decode(Response.self, from: data)
          } catch {
              print(&quot;failed to convert \(error.localizedDescription)&quot;)
          }
          
          guard let json = result else{
              return
          }
          
          print(&quot;Page: \(json.page)&quot;)
          print(&quot;Books: \(json.books.first)&quot;)
      })
      
      task.resume()
  }
  
  struct Response: Codable {
      var error: String
      var total: String
      var page: String
      var books: [MyBook]
  }
  </code></pre>
  <p>The problem is that I don't know how to call this function when view start. In this sample I'm getting the error:</p>
  <blockquote>
  <p>&quot;Function declares an opaque return type, but has no return statements
  in its body from which to infer an underlying type&quot;</p>
  </blockquote>
  <p>How can I fix it?</p>