我正在尝试在我的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];
根据我的测试:
我得到的崩溃错误是这个:
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'
EDIT / HINT:
超级简单。
@@ Vadian问我正确的问题。我只检索1个对象,所以正确的行应该是这个:
PFObject *CurrentUserThumbsDown = [PFObject objectWithoutDataWithClassName:@"UserRating" objectId:[downVote[0] valueForKey:@"objectId"]];
编辑:
下面的注释中提供的一个更好的主意是只获取getFirstObject,这是一个更好的主意:
PFObject *CurrentUserThumbsDown = [downvoteUser getFirstObject];