gpt4 book ai didi

ios - 在我的viewDidLoad中获取EXC_BAD_ACCESS

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

在我的iOS应用程序的viewDidLoad方法中,我具有以下代码行:

loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", "version number", nil]; 

并导致 EXC_BAD_ACCESS错误。我不知道为什么。除了该行所在的if / else语句的另一侧之外, viewDidLoad方法中没有其他东西使用该对象,因此不可能已经释放它。我只是不确定是什么问题。如果您想查看我的整个 viewDidLoad方法,则为:
- (void)viewDidLoad
{
[super viewDidLoad];
tapsBackground = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
tapsBackground.delegate = self;
[self.view addGestureRecognizer:tapsBackground];

saveChangesButton.hidden = YES;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePath = [documentsDirectory stringByAppendingPathComponent:@"presets.plist"];

if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
loadDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
}

else{
loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", "version number", nil];
[loadDict writeToFile:filePath atomically:YES];
}
}

最佳答案

问题是您在第二个字符串中缺少@,即"version number"

loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", "version number", nil];

它应该是,
loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", @"version number", nil];

关于ios - 在我的viewDidLoad中获取EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6825780/

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