Unable to infer complex closure return type; add explicit type to disambiguate

**import** Foundation

**struct** datatype : Identifiable {

**var** id : String

**var** name : String

**var** msg : String

**var** groupsShortcut : String

**var** retwetts : String

**var** likes : String

**var** pic : String

**var** url : String

**var** tagId : String


**struct** Topdatatype : Identifiable {

**var** id : String

**var** tag : String

**var** tweets : String


Ok, I thought you already solved the error.

Here’s what you can do. You need to figure out the error first, just remove each part, until the compiler stops complaining, you’ll know that that line is the culprit.

The error is not exactly helping at the moment, so we gotta do it old-style.

The compiler does not complain if I remove the if pic!= ""

As in, finished compiling to the end, or does it have different error?

Its ok if I remove this part but I need this check

I just want to make sure, since there is miscommunication earlier, does it finish the compilation without error if you remove if i.pic != "" part (along with the bracket)?

yes it finishes the compilation without error

This is curious, I’m not sure what could cause this. Could you take a screen shot of the one that successfully compiled? I wanna compare them.

I couldn't find anything really, but try this.

// Add new function in PostView
struct PostView {
  func tweetCell(data: datatype) -> some View {
    VStack {
      if i.groupsShortcut == self.shortcut {
        tweetCellTop ... 
        if pic != "" {
          tweetCellMiddle ...
        tweetCellBottom ...

Then in the ForEach, do

ForEach(observedData.datas, content: self.tweetCell(data:))

This is what I meant when I said to separate them into multiple pieces. So the compiler can figure them out separately. And we'll also get a more pinpoint location of the error.

What am I messing?

tweetCell is inside PostView And also the VStack encompassing the entire function

what about

Use of unresolved identifier 'i'

Oh right, you use i, I used data

You can do

func tweetCell(data i: datatype) -> some View {

I really wouldn’t advice that you tried SwiftUI as your first project (not one with so much complexity), compilers aren’t exactly helpful as of yet, and could hinder the learning.

There’s an -> some View at the end of tweetCell

Also there’s a VStack (with the {} bracket) covering the entire block in tweetCell.

your are awesome, that solved my problem. Thaaaanks

1 Like

Also checkout https://swift.org/documentation/api-design-guidelines/ for some naming guideline :)

1 Like

I've had the same problem half an hour ago. After all it appeared that a misspelled variable name inside the ForEach (actually in the if statement) causes this "Unable to infer complex closure return type; add explicit type to disambiguate"

Terms of Service

Privacy Policy

Cookie Policy