-
-
Notifications
You must be signed in to change notification settings - Fork 871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating objects with init(withoutDataWithObjectId:) causes crash in SwiftUI preview #1679
Comments
Thanks for opening this issue!
|
Tested and confirmed it works in the SwiftUI Preview with the code below:
It may be the case that the variables in your classes (User & Project) are declared as optionals therefore in breaks in the view when referenced.
|
Hey @eniok, thanks a lot for taking the time and testing this yourself! To emulate your test environment, I upgraded to macOS 13.0.1 and Xcode 14.1 and tried out your example in a new, empty Xcode App project; I just added Cocoapods with the Unfortunately I still get crashes in the SwiftUI preview, for the same reasons as before. Since the code worked for you, there must be a difference in our setup. Would you mind sharing details about yours? I'm running on a MacBook Pro M1 Max with macOS 13.0.1, using Cocoapods 1.11.3 and Parse 1.19.4. (The M1 is my main suspect...) I will list the runtime errors and workarounds again, with more detail:
// When setting properties, this fails...
user.firstName = "..."
// ... and this works:
user.setValue("...", forKey: "firstName")`
// When reading properties in SwiftUI, this fails...
Text(user.firstName ?? "Null")
// ... and this works:
Text(user.value(forKey: "firstName") as? String ?? "Null") Of course this is just a theoretical solution, in practice this is not usable -- it would mean to give up type safety when showing model values inside SwiftUI templates. P.S. I my main project where the problem was first encountered, I could not run any previews since the upgrade to Xcode 14, even if no Parse classes were involved in the preview. The reason is that Xcode executes some parts of the main app when initiating a preview, including the hooks which I use to initialize Parse. I had to add "preview checks" ( |
Hi @drbarto, The system I tested it also has an M1 (M1 Pro on a Macbook Pro), the environment has the following versions:
|
New Issue Checklist
Issue Description
In a Swift project using the Parse pod, I create a bunch of dummy objects using
init(withoutDataWithObjectId:)
for use in tests and SwiftUI previews. When running the app or unit tests, these objects can be created without problem; however, when trying to create them in the context of a SwiftUI preview, the process crashes.Steps to reproduce
To give an example, e.g. I have classes
User
andProject
defined as follows:Sample code for creating dummy objects:
Finally I want to provide the dummy objects to my UI code, so that it can be tested and previewed without a server connection:
Actual Outcome
Executing the above "dummy object creation" code works fine when running the app or the unit tests.
However, when executing it in the context of the Xcode SwiftUI preview window, it crashes with these errors:
When executing
User(withoutDataWithObjectId: "user_1")
:When executing
project.name = "..."
:I can avoid the 2nd issue with
setName
by replacing the call withproject.setValue("...", forKey: "name")
.However, I found no workaround for the 1st crash related to the classname.
Expected Outcome
The dummy objects can be created without crashing the process.
Environment
Client
Server
Database
Logs
none
The text was updated successfully, but these errors were encountered: