Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

ios - SwiftUI 2.0 CoreData issues with new project - 'Cannot find type 'Item' in scope'

[EDIT] I was hoping that Apple would have fixed what is obviously a bug. The solution is to clear the cache, close and reopen Xcode..

I am on Xcode Beta and starting a new project and without writing a single line of code I already get an error. I could not find anything online. Perhaps is this too new?

In the new version of Xcode I selected new Project,

selecting new project

then ticked the box with Core Data

ticking the box Core Data

If I do not tick the box I would get the usual Xcode SwiftUI template with "hello world", but ticking the Core Data box I get a ton more template code from Apple and without touching anything and without changing a single line of code, I get an error message compiling it..

Error

The error is: "Cannot find Item in scope"

Quite frustrating, especially because all tutorials I have start with the classic 'AppDelegate' file configuration.. while the new SwiftUI is 'universal'!

I checked the file .xcdatamodeld and it looks fine, and has the 'Item' entity. Why it doesn't compile?

So I am now at a loss, is there a solution or this is a bug and need to wait that Apple releases a fix. If so I do not need to start with a new project until then!

PS Today I cleaned the cache with CMD-ALT-SHIFT-K, closed Xcode, deleted the app from the simulator, reopened, rebuilt and it did compile.. but nothing in the simulator! We are making progress! Still I did not change a line of code. Everything is the Apple template yet!

enter image description here

question from:https://stackoverflow.com/questions/63603754/swiftui-2-0-coredata-issues-with-new-project-cannot-find-type-item-in-scope

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The normal Xcode clearing works for me:

  1. Clean build folder (SHIFT + COMMAND + K)

  2. Quit Xcode completely

  3. Delete the project's contents in, DerivedData/{Project Name}_some_hash

    The default location is ~/Library/Developer/Xcode/DerivedData, but if it's nowhere to be found, check the Derived Data property under, Xcode → Preferences → Locations

  4. Try again (run Xcode & build)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...