解析增量键使iOS应用程序崩溃

问题描述 投票:0回答:1

我正在尝试在我的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];

根据我的测试:

  • 如果我删除了递增密钥,它将不会崩溃;但它不会做任何事情
  • 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'

EDIT / HINT:

  • 如果我将PFObject中的objectID更改为数据库中的实际objectId,它实际上是有效的,所以问题一定出在NSArray中。
ios objective-c parse-platform increment
1个回答
0
投票

超级简单。

@@ Vadian问我正确的问题。我只检索1个对象,所以正确的行应该是这个:

PFObject *CurrentUserThumbsDown = [PFObject objectWithoutDataWithClassName:@"UserRating" objectId:[downVote[0] valueForKey:@"objectId"]];

编辑:

下面的注释中提供的一个更好的主意是只获取getFirstObject,这是一个更好的主意:

PFObject *CurrentUserThumbsDown = [downvoteUser getFirstObject];
© www.soinside.com 2019 - 2024. All rights reserved.