After I did update Xcode, I've got this error. The new file was create with the right target and in the right folder but I still got that error. Can anyone point me in the right direction??
Issue with founding any File.swift in the scope after update to Xcode 14.3.1
If the project built with no errors previously, clean the build folder and try building again. Choose Product > Clean Build Folder in Xcode to clean the build folder.
If you still get a build error, show the code for Controller
. What is Controller
? What is the following code supposed to do?
.onAppear {
Controller()
}
When showing code, paste it as text and put it in a code block. The code block button is the fourth button from the left in the group of formatting buttons at the bottom of the post editor. You can also use Markdown syntax for a code block by putting three backticks on the line above and below the code in the block.
https://www.markdownguide.org/extended-syntax/#fenced-code-blocks
Code is easier to read in a text block than in a screenshot. Plus, people can copy and paste the text from a code block.
First thanks so much for your reply. I'll attach here thee code snippet
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
}
.onAppear{
ProductManager().loadProduct()
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Below ModelView called ProductManager, which contain an empty function just to dimostrate the issue:
class Products:ObservableObject{
func loadProduct(){
}
}
I still got the same errore saying: "ProductManager" can not be found in scope... I did check also the inspector and the target is set correctly...
The name of the class you showed is Products
, not ProductManager
. That is why the compiler can't find ProductManager
.
Does the error go away if you change the name of the class to ProductManager
or if you change ProductManager
to Products
in the .onAppear
block?
You also need to create an instance of your class to call the function.
.onAppear {
let manager = ProductManager()
manager.loadProduct()
}
In a real SwiftUI app you would add a property to the view.
@StateObject manager = ProductManager()
My examples assume you changed the name of the class from Products
to ProductManager
.
I recommend taking a course like Hacking with Swift's 100 Days of SwiftUI to learn SwiftUI. A course like that would help you deal with problems like the one you asked about here.
https://www.hackingwithswift.com/100/swiftui