<Objective-C syntax

I am trying to do something very trivial here, but the program exits with "EXC_BAD_ACCESS" in NSLog. I am trying to populate a mutable array with several dictionaries as follows:

NSMutableArray *_recipientsMutArray = [[NSMutableArray alloc] init];

NSDictionary *r1 = [[NSDictionary alloc] initWithObjectsAndKeys: @"firsValue", @"firstKey", @"secondValue", @"secondKey", nil];

[_recipientsMutArray addObject:r1];

[r1 release];

Why?

+3
source share
1 answer

The code you provided is in order and should not be called EXC_BAD_ACCESS, however you are mentioning an accident with NSLog. A common mistake to make with NSLogis to provide a C style string for the format string, not NSString. The following are the errors:

int i = 4;
NSLog("%d", i); // oh no!

Instead, you need to make sure the NSLogfirst argument NSString, for example:

int i = 4;
NSLog(@"%d", i); // yay!
+2
source

Source: https://habr.com/ru/post/1757123/


All Articles