【发布时间】:2020-01-19 18:36:22
【问题描述】:
我试图在我的 Parse 数据库中将名为“ThumbsDown”的列增加 1,但是我执行这种递增的代码行使应用程序崩溃。该列的类型为“数字”。
PFQuery *downvoteUser = [PFQuery queryWithClassName:@"UserRating"];
[downvoteUser whereKey:@"User" equalTo:PFUser.currentUser.username];
NSArray *downVote = [downvoteUser findObjects];
NSLog(@"objectID : %@", [downVote valueForKey:@"objectId"]);
NSLog(@"ThumbsDown : %@", [downVote valueForKey:@"ThumbsDown"]);
// Here we update the Rated column in Event Class
PFObject *CurrentUserThumbsDown = [PFObject objectWithoutDataWithClassName:@"UserRating" objectId:[downVote valueForKey:@"objectId"]];
[CurrentUserThumbsDown incrementKey:@"ThumbsDown"];
[CurrentUserThumbsDown save];
根据我的测试:
- 如果我删除incrementKey,它不会崩溃;但它不会做任何事情
- NSLogs 实际上返回预期值,从云中获取。
- 我无法从保存中打印出错误,因为它在捕捉到它之前就崩溃了
我得到的崩溃错误是这个:
2020-01-19 19:25:41.024887+0100 Sporteve[39724:418054] Warning: A long-running operation is being executed on the main thread.
Break on warnBlockingOperationOnMainThread() to debug.
2020-01-19 19:25:41.025422+0100 Sporteve[39724:418243] -[__NSSingleObjectArrayI length]: unrecognized selector sent to instance 0x600001572ef0
2020-01-19 19:25:41.027731+0100 Sporteve[39724:418243] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectArrayI length]: unrecognized selector sent to instance 0x600001572ef0'
编辑/提示:
- 如果我将 PFObject 中的 objectID 更改为数据库中的真实 objectId,它实际上可以工作,所以问题一定出在 NSArray 中。
【问题讨论】:
-
您期望有多少对象匹配查询?
标签: ios objective-c parse-platform increment