Home > Software design >  Cannot find type 'View' in scope
Cannot find type 'View' in scope

Time:11-09

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.

CodePudding user response:

add to top of file

import SwiftUI

  • Related