I have ran into this problem on a project and have boiled it down to the following sample code:
#import <map>
typedef std::map<int, int> exampleMap;
@interface ViewController ()
@property (nonatomic, assign) exampleMap map;
@end
@implementation ViewController
- (IBAction)iterateWithSelf:(id)sender
{
for (exampleMap::iterator iter = self.map.begin(); iter != self.map.end(); ++iter)
{
NSLog(@"We should never hit this line as map is empty");
}
}
- (IBAction)iterateWithIVar:(id)sender
{
for (exampleMap::iterator iter = _map.begin(); iter != _map.end(); ++iter)
{
NSLog(@"We should never hit this line as map is empty");
}
}
@end
- iterateWithIVar:
executes fine and nothing is logged to the console.
- iterateWithSelf:
goes into the for loop, prints a line to the console and then crashes with EXC_BAD_ACCESS
I then tried inserting... self.map.insert(std::pair<int, int>(0, 1));
appears to affect nothing while _map.insert(std::pair<int, int>(0, 1));
adds an iteration to iterateWithIvar
Any ideas?