Learn Courses My Dashboard

Both the simulator and preview are not working

Hi there,

All of my code is running well on iphone, but is not showing on preview and simulator. I have tried many methods from forum such as using sudo command, but nothing changed yet. Besides, I also reinstalled Xcode 12.5 onto my mac as suggested from forum.
The preview error begins like this, “HumanReadableNSError:…” And the simulator is always black.
Right now I have followed this class to IOS database course with my iphone XR as the simulator. It will be of great help if anyone can solve the preview and simulator problem for me. Thank you!

Welcome to the community!

That’s interesting it works when running on your device but not the simulator or canvas?

If you create a brand new hello world project (without changing anything) does that run on the simulator?

Getting the Preview to work can be tricky depending on the structure of your Application.

For example, if you are using a ViewModel which conforms to ObservableObject and you have an array of data as the Published property that you are using in ContentView then the convention in ContentView is to declare an instance of the ViewModel as either an ObservedObject or StateObject or an EnvironmentObject depending on the structure of your Application.

For the Preview to work is depends on what option you have chosen in the View as to what setup you need to do in the Preview.

It would probably help if you provide some code examples of what you are trying to do so that anyone replying to your question can advise accordingly.

Hi Parker,

The preview and simulator problems are solved automatically after purchasing the Apple developer membership and restarting my mac. Honestly I have no idea what’s going on here. However, I am happy the problem is solved. Thank you!