在我的viewDidLoad中获取EXC_BAD_ACCESS

use*_*425 1 nsmutabledictionary ios

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

loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", "version number", nil]; 
Run Code Online (Sandbox Code Playgroud)

它会导致EXC_BAD_ACCESS错误.我不知道为什么.viewDidLoad除了该行所在的if/else语句的另一侧之外,该方法中没有其他任何东西使用该对象,因此无法将其释放.我只是不确定问题是什么.如果你想看看我的整个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];
    }
}
Run Code Online (Sandbox Code Playgroud)

Dee*_*olu 6

问题是你@在第二个字符串中缺少ie "version number".

loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", "version number", nil];
Run Code Online (Sandbox Code Playgroud)

它应该是,

loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", @"version number", nil];
Run Code Online (Sandbox Code Playgroud)