gpt4 book ai didi

ios - 在 NSDictionary 中插入 nil 时不会抛出异常

转载 作者:行者123 更新时间:2023-11-28 18:19:13 25 4
gpt4 key购买 nike

所以我正在努力从用户的 Facebook 相册中提取照片,由于某种原因,NSDictionary 在插入 nil 时不会抛出异常。我已经在真实设备和 iOS 模拟器(均为 iOS 7)上对其进行了测试。也许调试器崩溃了,也许是 Facebook SDK 的错误。无论如何,我愿意听取您的意见。

更新:还有一件事我忘了提。在调试器中,在字典中插入 nil 对象后,调试器本身继续执行程序。而且我什至没有按下按钮“继续执行程序”。

这是片段

- (void)downloadAlbumsWithCompletionBlock:(void (^)(NSArray *albums, NSError *error))completionBlock;
{
[FBRequestConnection startWithGraphPath:@"/me/albums"
parameters:nil
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (error)
{
NSLog(@"%@", error.localizedDescription);
completionBlock(nil, error);
}
else
{
NSMutableArray *data = [result objectForKey:@"data"];
NSMutableArray *albums = [NSMutableArray new];
for (NSMutableDictionary *dict in data)
{
NSString *albumID = dict[@"id"];
NSString *coverPhotoID = dict[@"cover_photo"];
// coverPhotoID gets nil and then successfully gets put in NSDictionary
// You can just write "NSString *coverPhotoID = nil;".
NSString *description = dict[@"description"];
NSString *name = dict[@"name"];
NSDictionary *album = @{@"album_id": albumID,
@"album_cover_photo_id": coverPhotoID,
@"album_description": description,
@"album_name": name };
// Here an exception should be thrown but for some reason
// we just quit out of the method. Result would be the same if we put
// empty "return;" statement.
// If we explicitly put nil, like
// @"album_cover_photo_id": nil
// we get compiler error.
[albums addObject:album];
}
completionBlock(albums, nil);
}
}];
}

最佳答案

你写道:

// Here an exception should be thrown but for some reason
// we just quit out of the method. Result would be the same if we put empty "return;" statement.

很可能在某处捕获了异常。尝试在 Objective-C 异常抛出上设置断点(在 Xcode 中,转到“断点”选项卡,单击左下角的 + 并选择“添加异常断点”。确保参数设置为“Objective-C 异常”和“抛出时中断”)。

关于ios - 在 NSDictionary 中插入 nil 时不会抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23808530/

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