gpt4 book ai didi

ios - 使用BOOL创建NSDictionary时收到EXC_BAD_ACCESS(Code = EXC_ARM_DA_ALIGN)

转载 作者:行者123 更新时间:2023-12-01 17:25:44 26 4
gpt4 key购买 nike

我正在尝试创建一个包含3个元素的字典对象,其中之一是BOOL值。我收到一个EXC_BAD_ACCESS(Code = EXC_ARM_DA_ALIGN,address = 0x5),其中使用[NSDictionary dictionaryWithObjectsAndKeys:object,key,nil]将BOOL存储为对象

以下代码有什么问题:

- (void) retrieveAchievmentMetadata
{
[GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:
^(NSArray *descriptions, NSError *error) {
if (error != nil)
{
// Process the error.
}
if (descriptions != nil)
{

[self setAchievementDescriptions:[[NSMutableDictionary alloc] init]];

for (GKAchievementDescription *achievementDescription in descriptions) {

NSDictionary *achievementData = [NSDictionary dictionaryWithObjectsAndKeys:
[achievementDescription achievedDescription], @"Achieved Description",
[achievementDescription maximumPoints], @"Maximum Points",
[NSNumber numberWithBool:FALSE], @"Level Is Completed", nil];

[achievementDescriptions setObject:achievementData forKey:[achievementDescription identifier]];

}
}
}];

}

EXC_BAD_ACCESS错误在行上发生
[NSNumber numberWithBool:FALSE], @"Level Is Completed", nil];

最佳答案

崩溃的原因是[achievementDescription maximumPoints]maximumPoints属性返回的是NSInteger而不是NSNumber实例。

将其更改为:[NSNumber numberWithInteger:[achievementDescription maximumPoints]], @"Maximum Points", ...

关于ios - 使用BOOL创建NSDictionary时收到EXC_BAD_ACCESS(Code = EXC_ARM_DA_ALIGN),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22384990/

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