You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XCode 16初始化Parse报错:类名不能以下划线开头

Parse初始化崩溃问题求助

环境信息

  • XCode版本:16.0 (16A242d)
  • macOS版本:14.5 (23F79)
  • Parse安装方式:先后尝试CocoaPods、Package Dependency安装最新版本,问题未解决

初始化代码

[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
            configuration.applicationId = @"myAppId";
            configuration.clientKey = nil;
            configuration.server = @"myParseServerUrlStringHostedonHeroku";
}]];

运行崩溃日志

*** 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
)

问题根源调试分析

  1. 崩溃触发路径:初始化Parse后,PFCurrentInstallationController尝试获取当前安装对象时,调用+[PFObject object]方法
  2. +[PFObject object]关键代码:
+ (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];
}
  1. 核心问题:
    • 此处self为PFInstallation类,其parseClassName返回"_Installation"
    • [[self subclassingController] subclassForParseClassName:@"_Installation"]返回nil,导致代码 fallback 到[PFObject class]
    • 调用[PFObject objectWithClassName:@"_Installation"]时,触发+[PFObject(Private) _assertValidInstanceClassName:]校验,该方法不允许类名以下划线开头,最终抛出异常

怀疑方向

PFInstallation子类未在PFObjectSubclassingController的registerSubclass:方法中完成注册,导致子类控制器无法匹配到_Installation对应的PFInstallation类,只能用PFObject处理该类名,触发校验错误。

内容的提问来源于stack exchange,提问作者Harshal Karande

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 21:15:00