gpt4 book ai didi

从 Parse.com 的 CloudCode 接收空数组时 iOS 崩溃

转载 作者:行者123 更新时间:2023-11-28 22:06:31 25 4
gpt4 key购买 nike

我正在尝试从返回字典的“Parse.com 的云代码”中获取查询。字典包含两个键,“groups”和“invites”,都是数组。

当其中一个key为空数组时,会出现如下错误:

2014-05-23 17:14:03.967 XXX[2267:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]' * First throw call stack: (0x2d589f0b 0x37d20ce7 0x2d4c7cff 0x2d4c7ac3 0x1acd5b 0x1acfef 0xddb95 0xdda07 0xedd4d 0x2fdd3d23 0x2fe83057 0x2fdd3d23 0x2fe38e7f 0x2fe38e09 0x2fdb1b73 0x2d555039 0x2d5529c7 0x2d552d13 0x2d4bd769 0x2d4bd54b 0x3242a6d3 0x2fe1c891 0xe3805 0x3821eab7) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

云代码函数如下:

Parse.Cloud.define("GroupsAndInvites",function(request,response){
var user = request.user;
//query memberships and invites for the current user
var membershipQuery = new Parse.Query("Membership").include("group").equalTo("user",user);
var inviteQuery = new Parse.Query("Invite").include("from").include("group").equalTo("to",user);

//make promises
var membershipPromise = membershipQuery.find();
var invitePromise = inviteQuery.find();

//call when both queries are done
Parse.Promise.when(membershipPromise,invitePromise).then(function(memberships,invites){
//make an array of groups instead of memberships
var groups = [];
for(var i=0;i<memberships.length;i++){
groups.push(memberships[i].get("group"));
}
//return groups and invites
response.success({
"groups":groups,
"invites":invites
});
});
});

这是我在前端实现的那个功能:

  [PFCloud callFunctionInBackground:@"GroupsAndInvites" withParameters:nil block:^(NSDictionary *dict, NSError *error) {
if (!error) {
NSMutableArray *groupsArray = [NSMutableArray array];
NSMutableArray *invitesArray = [NSMutableArray array];

for (BVYGroup *group in dict[@"groups"]) {
[groupsArray addObject:group];
}

for (BVYInvite *invite in dict[@"invites"]) {
[invitesArray addObject:invite];
}

if ([strongDelegate respondsToSelector:@selector(groupStream:didFetchGroups:andInvites:)]) {
[strongDelegate groupStream:self didFetchGroups:groupsArray andInvites:invitesArray];
}
} else {
if ([strongDelegate respondsToSelector:@selector(groupStream:didFailToFetchGroupsWithError:)]) {
[strongDelegate groupStream:self didFailToFetchGroupsWithError:error];
}
}
}];

错误发生在检索响应时。它没有到达检查错误的 if 语句。

对为什么会发生这种情况有任何见解吗?
提前谢谢你。

最佳答案

您不能将 nil 插入到 Objective-C 集合中。如果您需要在 Objective-C 集合中表示一个 nil 值,请改用 [NSNull null]

关于从 Parse.com 的 CloudCode 接收空数组时 iOS 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23838591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com