解析“键不能为”nil“错误on [PFObject saveInBackground](Cocoa) [英] Parse "key cannot be nil" error on [PFObject saveInBackground] (Cocoa)

查看:208
本文介绍了解析“键不能为”nil“错误on [PFObject saveInBackground](Cocoa)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在现有的Mac OS X应用程序中试用了Parse SDK。我按照Parse快速入门指南中的设置步骤,包括将Parse库的导入添加到我的AppDelegate .m文件并调用:

I'm trying out the Parse SDK in an existing Mac OS X application. I followed the setup steps in the Parse Quickstart guide, including adding an import for the Parse library to my AppDelegate .m file and calling:

[Parse setApplicationId:kParseApplicationID clientKey:kParseClientKey];

我使用的两个常数在一个也被导入的Constants文件中定义。

in the applicationDidFinishLaunching method. The two constants I use are defined in a Constants file which is also imported.

指南最后说:然后将此代码复制并粘贴到您的应用程序中,示例在viewDidLoad方法(或在运行应用程序时调用的另一个方法内部)

Towards the end the guide says: "Then copy and paste this code into your app, for example in the viewDidLoad method (or inside another method that gets called when you run your app)"

所以我将Parse头文件导入我的主视图控制器.m文件并将其代码复制并粘贴到其viewDidLoad方法中:

So I imported the Parse header file into my main view controller .m file and copied and pasted their code into its viewDidLoad method:

PFObject * testObject = [PFObject objectWithClassName:@TestObject];
testObject [@foo] = @bar;
[testObject saveInBackground];

当运行时,我碰到一个异常,其消息是setObjectForKey:key can not be nil在最后一行。不是在上一行,我实际上设置的键的对象。此外,如果我停在上一行和PO testObject,testObject.allKeys或testObject [@foo],它们都显示键foo的非nil值。更进一步,如果我把这个代码移动到AppDelegate的applicationDidFinishLaunching方法的结尾,代码执行没有任何错误,TestObject显示在我的Parse应用程序仪表板中。

When this runs, I hit an exception whose message is "setObjectForKey: key cannot be nil" on that last line. Not on the previous line where I'm actually setting the object for the key. Furthermore, if I stop on the previous line and PO testObject, testObject.allKeys, or testObject[@"foo"], they all show non-nil values for the key "foo". And still furthermore, if I move this code to the end of the AppDelegate's applicationDidFinishLaunching method, the code executes without any errors, and the TestObject shows up in my Parse application dashboard.

有人能告诉我我做错了什么?我真的想进一步探索,但这对我来说是一个真正的阻碍。

Can somebody tell me what I'm doing wrong? I'd really like to explore further, but this is a real blocker for me.

这是从稍微更多涉及的OS X应用程序的控制台日志,也发生在[ ParseObject saveInBackgroundWithBlock:]:

Here's the console log from a slightly more involved OS X app, also occurring on [ParseObject saveInBackgroundWithBlock:]:

2015-06-03 16:55:56.046 TestApp [15795:15954566] An uncaught exception was raised
2015-06-03 16:55:56.046 TestApp [15795:15954566] *** setObjectForKey: key cannot be nil
2015-06-03 16:55:56.046 TestApp [15795:15954566] (
0   CoreFoundation                      0x00007fff8fb0103c __exceptionPreprocess + 172
1   libobjc.A.dylib                     0x00007fff978e476e objc_exception_throw + 43
2   CoreFoundation                      0x00007fff8f9e7c66 -[__NSDictionaryM setObject:forKey:] + 1174
3   ParseOSX                            0x000000010011adbb __74-[PFMultiProcessFileLockController beginLockedContentAccessForFileAtPath:]_block_invoke + 129
4   libdispatch.dylib                   0x000000010026cd43 _dispatch_client_callout + 8
5   libdispatch.dylib                   0x000000010026e0b1 _dispatch_barrier_sync_f_invoke + 348
6   ParseOSX                            0x000000010011ad15 -[PFMultiProcessFileLockController beginLockedContentAccessForFileAtPath:] + 127
7   ParseOSX                            0x00000001000f61ea +[PFObject(Private) _objectFromDataFile:error:] + 207
8   ParseOSX                            0x000000010010f231 +[PFUser(Private) _getCurrentUserWithOptions:] + 611
9   ParseOSX                            0x00000001000fc4bd -[PFObject(Private) saveAsync:] + 118
10  ParseOSX                            0x00000001000e1d25 -[PFTaskQueue enqueue:] + 188
11  ParseOSX                            0x00000001000ff06b -[PFObject saveInBackground] + 121
12  ParseOSX                            0x00000001000ff270 -[PFObject saveInBackgroundWithBlock:] + 49
13  TestApp                             0x0000000100001827 +[SBTParseTranslation saveDBObjectToParse:] + 183
14  TestApp                             0x0000000100031fb4 -[SWBMainWindowViewController showRecordForItem:] + 3124
15  TestApp                             0x0000000100031268 -[SWBMainWindowViewController showRecordForID:] + 184
16  TestApp                             0x0000000100031080 -[SWBMainWindowViewController finishLoad] + 448
17  TestApp                             0x0000000100030eb1 -[SWBMainWindowViewController loadData] + 97
18  TestApp                             0x0000000100030dd5 -[SWBMainWindowViewController viewDidLoad] + 725


推荐答案

在我的情况下,ios7崩溃与saveInBackground因为podfile包含:

In my case ios7 was crashing with saveInBackground since podfile contained:


平台:ios,'8.0'

platform :ios, '8.0'

,部署目标为7.0。我替换为

and deployment target was 7.0. I replaced with


平台:ios,'7.0'

platform :ios, '7.0'

然后清理并再次生成

这篇关于解析“键不能为”nil“错误on [PFObject saveInBackground](Cocoa)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆