Reputation: 275
in my iOS app's viewDidLoad
method, i have the following line of code:
loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", "version number", nil];
and it causes an EXC_BAD_ACCESS
error. i don't know why. nothing else in the viewDidLoad
method uses the object except the other side of the if/else statement this line is in, so there's no way it could have been released already. i'm just not sure what the problem is. if you want to see my whole viewDidLoad
method, here it is:
- (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];
}
}
Upvotes: 1
Views: 811
Reputation: 44633
The problem is that you are missing @
in the second string i.e. "version number"
.
loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", "version number", nil];
It should be,
loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", @"version number", nil];
Upvotes: 6
Reputation: 7644
I've faced the same issue once. Try this, it worked for me:
self.loadDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1.0", "version number", nil];
I'm assuming you have already made loadDict a property. You can use Product>Profile>allocations to pin-point the problem in such cases.
Upvotes: 0