cannot find in scope

struct viewdetail: View { @State var text1:String = "" @State var tip1:String = "" @State var text23:String = "" @State var tip23:String = "" var body: some View { Text(text1);Text(tip1);Text(text23);Text(tip23)

}   }
func detailline(costa:inout [Double],tipa:inout [Double]) {
    print(costa,tipa)
    text1 = "125"                                                 Cannot find 'text1' in scope                       print("detail")
}
Answered by Claude31 in 819035022

It's normal, it is out of scope :

If you format the code properly:

struct viewdetail: View {
    @State var text1:String = ""
    @State var tip1:String = ""
    @State var text23:String = ""
    @State var tip23:String = ""
    
    var body: some View {
        Text(text1);Text(tip1);Text(text23);Text(tip23)
    }
}

func detailline(costa:inout [Double],tipa:inout [Double]) {
    print(costa,tipa)
    text1 = "125"              //         Cannot find 'text1' in scope           
    print("detail")
}

func îs defined OUT of viewDetail.

Hence, text1 in detailing is not defined.

You have to change as follows:

struct ViewDetail: View {
    @State var text1:String = ""
    @State var tip1:String = ""
    @State var text23:String = ""
    @State var tip23:String = ""
    
    func detailLine(costa:inout [Double],tipa:inout [Double]) {
        print(costa,tipa)
        text1 = "125"              //    Now, Can find 'text1' in scope
        print("detail")
    }

    var body: some View {
        Text(text1);Text(tip1);Text(text23);Text(tip23)
    }
}

Note also I changed the caps on names to follow Swift rules.

PS: when you ask a question:

  • format code with code formatter tool
  • take time to formulate the question in the text, not only the title.
  • Don't forget to close the thread once you've got the correct answer, by marking the answer as correct.

Please answer.

I put all your suggestions in except for Gridrow. There were too many errors including g.size cannot be found in scope. Now I just have to put in Another View. All I did was create an array with 44 texts. Please help me.

There's too many replies in here. I'm going to post elsewhere.

We've given you complete sections of working code and shown you how to use them. You've responded that you didn't try them or don't know how to try them.

At this point, I am no longer willing to help you. I've done my best, but if you're unwilling to try our responses, why should we bother wasting our time?

i wish you well in your coding endeavours, but I cannot help you anymore.

No please help me. I got dementia. I'm willing to try your responses I just don't know how. Please just this one last time. I won't bother you anymore.

Claude31 gave you a COMPLETE solution to your problems. You should take that entire set of code and replace your code with that. What I suspect you have done is copied and pasted bits of it from these pages into your Xcode and have missed bits out - that would certainly explain why your GridRow parts failed, because you didn't see the GeometryReader that was added in further up.

it is extremely difficult to help you when we give you the solution and you hack it about and don't follow what we've given you or told you to do. We cannot help you if you cannot do the simplest of things. If g.size can't be found when you paste some code into your Xcode you should look for where g was declared. If you can't do that, then you need to read a more basic tutorial on coding.

You're right. I didn't see GeometryReader that was added further up. I'm going to try to put GridRow back in.

cannot find in scope
 
 
Q