I am getting this error at initialization of Parse. Most likely it is because I updated to XCode Version 16.0 (16A242d). MacOS is 14.5 (23F79).
I have installed Parse as a pod. Also tried to remove it and install latest version as a Package Dependency but same error.
[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
configuration.applicationId = @"myAppId";
configuration.clientKey = nil;
configuration.server = @"myParseServerUrlStringHostedonHeroku";
}]];
Here is what I get when I run the app: (No errors while compiling.)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: Invalid class name. Class names cannot start with an underscore.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001804ae0f8 __exceptionPreprocess + 172
1 libobjc.A.dylib 0x0000000180087db4 objc_exception_throw + 56
2 CoreFoundation 0x00000001804ae008 -[NSException initWithCoder:] + 0
3 myApp.debug.dylib 0x0000000106d2f1f8 +[PFObject(Private) _assertValidInstanceClassName:] + 180
4 myApp.debug.dylib 0x0000000106d37598 -[PFObject init] + 436
5 myApp.debug.dylib 0x0000000106d37898 -[PFObject initWithObjectState:] + 92
6 myApp.debug.dylib 0x0000000106d379cc +[PFObject objectWithClassName:objectId:completeData:] + 248
7 myApp.debug.dylib 0x0000000106d37ae0 +[PFObject objectWithClassName:] + 80
8 myApp.debug.dylib 0x0000000106d37fcc +[PFObject object] + 252
9 myApp.debug.dylib 0x0000000106cf6bdc __56-[PFCurrentInstallationController getCurrentObjectAsync]_block_invoke.9 + 452
10 myApp.debug.dylib 0x0000000106a64f18 __62-[BFTask continueWithExecutor:successBlock:cancellationToken:]_block_invoke + 124
11 myApp.debug.dylib 0x0000000106a64848 __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke + 88
12 myApp.debug.dylib 0x0000000106a615c0 __29+[BFExecutor defaultExecutor]_block_invoke_2 + 152
13 myApp.debug.dylib 0x0000000106a61da0 -[BFExecutor execute:] + 88
14 myApp.debug.dylib 0x0000000106a64b24 __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke.15 + 44
15 myApp.debug.dylib 0x0000000106a642f4 -[BFTask runContinuations] + 508
16 myApp.debug.dylib 0x0000000106a63cd8 -[BFTask trySetResult:] + 208
17 myApp.debug.dylib 0x0000000106a65a50 -[BFTaskCompletionSource trySetResult:] + 88
18 myApp.debug.dylib 0x0000000106ce88fc __28-[PFAsyncTaskQueue enqueue:]_block_invoke_2 + 216
19 myApp.debug.dylib 0x0000000106a64848 __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke + 88
20 libdispatch.dylib 0x00000001022cbec4 _dispatch_call_block_and_release + 24
21 libdispatch.dylib 0x00000001022cd73c _dispatch_client_callout + 16
22 libdispatch.dylib 0x00000001022d05a0 _dispatch_queue_override_invoke + 1320
23 libdispatch.dylib 0x00000001022e136c _dispatch_root_queue_drain + 372
24 libdispatch.dylib 0x00000001022e1f18 _dispatch_worker_thread2 + 256
25 libsystem_pthread.dylib 0x00000001022277d8 _pthread_wqthread + 224
26 libsystem_pthread.dylib 0x00000001022265d4 start_wqthread + 8
After debugging, this was causing the trouble: In PFObject:
+ (instancetype)object {
PFConsistencyAssert([self conformsToProtocol:@protocol(PFSubclassing)],
@"Can only call +object on subclasses conforming to PFSubclassing");
NSString *className = [(id<PFSubclassing>)self parseClassName];
Class class = [[self subclassingController] subclassForParseClassName:className] ?: [PFObject class];
return [class objectWithClassName:className];
}
NSString *className = [(id<PFSubclassing>)self parseClassName];
in this line className comes out to be "_Installation" because in PFInstallation there is:
+ (NSString *)parseClassName {
return @"_Installation";
}
Also, [[self subclassingController] subclassForParseClassName:className]
return nil.
Spent almost entire day on this without breaks and frustrated. All I have a doubt on is that the subclasses are not registering in Parse->Core->PFObjectSubclassingController:
- (void)registerSubclass:(Class<PFSubclassing>)kls {
pf_sync_with_throw(_registeredSubclassesAccessQueue, ^{
[self _rawRegisterSubclass:kls];
});
}
which gives a nil at [[self subclassingController] subclassForParseClassName:className]
.
Please help! Desperately in need. Thank you!
We ran into the same issue. Simple fix is to register your PFObject classes at app start.
On macOS Swift, it can be done here.
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
PFInstallation.registerSubclass()
PFUser.registerSubclass()
PFSession.registerSubclass()
PersonClass.registerSubclass()
}
we found it to be more convenient to do it here:
override func viewDidLoad() {
super.viewDidLoad()
let configuration = ParseClientConfiguration {
$0.applicationId = Constants.PARSE_APPLICATION_ID
$0.clientKey = Constants.PARSE_CLIENT_KEY
$0.server = Constants.PARSE_SERVER
}
Parse.initialize(with: configuration)
PFInstallation.registerSubclass()
PFUser.registerSubclass()
PFSession.registerSubclass()
PersonClass.registerSubclass()
}
assuming your classes, like our PersonClass above, conforms to the PFObject, PFSubclassing protocols