2

I am following this tutorial: here and I am running into an issue. The issue is that when I do

struct ContentView: View {
    @State private var location: CGPoint = CGPoint(x: 50, y: 50) // 1
    
    var body: some View {        
        RoundedRectangle(cornerRadius: 10)
            .foregroundColor(.pink)
            .frame(width: 100, height: 100)
            .position(location) // 2
    }
}

I get the following issue: "Cannot find type 'View' in scope".

I don't know how to solve this issue. I've seen other StackOverflow posts with the user having a variation of the issue and the answer is to restart Xcode and it seems to fix it. I've tried that and it does not work.

I'm also wondering what does this error message indicates? I have seen other users use it without issue.

This is also my first time using struct's so I don't know if I need to do other stuff. I'm a beginner so any tips for doing stuff like this are super helpful.

2
  • 7
    Have you imported this? import SwiftUI Commented Nov 8, 2021 at 8:08
  • 1
    To clarify the previous comment that I am sure is to the point, if you choose to create a new SwiftUI file in your project you get the import statement for free but if you create a new Swift file it will instead use import Foundation so then you manually need to add the import statement and that is always added before the rest of your code at the top. Commented Nov 8, 2021 at 9:29

1 Answer 1

6

add to top of file

import SwiftUI

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.