-
-
Notifications
You must be signed in to change notification settings - Fork 876
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest versions of Parse Server and the Parse ObjC SDK.
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
and Project
defined as follows:
class User: PFUser {
@NSManaged var firstName: String?
@NSManaged var lastName: String?
}
class Project: PFObject, PFSubclassing {
class func parseClassName() -> String { "Project" }
@NSManaged var name: String?
}
Sample code for creating dummy objects:
let user = User(withoutDataWithObjectId: "user_1")
user.firstName = "..."
user.lastName = "..."
user.email = "customer@test.com"
let project = Project(withoutDataWithObjectId: "project_1")
project.name = "..."
Finally I want to provide the dummy objects to my UI code, so that it can be tested and previewed without a server connection:
struct UsersView_Previews: PreviewProvider {
static var previews: some View {
SomeFancyView(user: user, project: project)
}
}
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")
:
MyApp crashed due to an uncaught exception
NSInvalidArgumentException
.
Reason: Invalid class name. Class names cannot start with an underscore.
When executing project.name = "..."
:
MyApp crashed due to an uncaught exception
NSInvalidArgumentException
.
Reason: -[PFObject setName:]: unrecognized selector sent to instance 0x600001c74480.
I can avoid the 2nd issue with setName
by replacing the call with project.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
- Parse ObjC SDK version 1.19.4 (Cocoapods / Xcode 13.4.1)
Server
- does not apply
Database
- does not apply
Logs
none