I'm receiving a EXC_BAD_ACCESS-error from trying to manipulate a string, and I'm not sure exactly where it goes wrong.
The string is a property assigned as follows:
.h-file
.m-file
I'm using it to update the plist currently loaded into the Array Controller which is bound to and thus populates a TableView.
In my .m-file I have a function UpdateCurrentPlistString that updates that string and adds a number to it.
Starting-value is "MENU" (which will read "MENU.plist" when in a later function I use its value to load the plist), and pressing row 1 in my tableview will give the string "MENU_1", and so on.
This works fine the first time around, but the second time the function is called I receive the EXC_BAD_ACCESS-error.
Strangely enough, altering the code a little for debugging-purposes, this does NOT give any errors:
This leads me to the conclusion that the problem might have to do with the way I concat the string with the row-number. Could it be that the format of the string is altered, or is there something more nefarious lurking inside this code?
The string is a property assigned as follows:
.h-file
Code:
#import <Cocoa/Cocoa.h>
@interface TableViewController : NSTableView <NSTableViewDelegate> {
// other stuff...
NSString *str_CurrentPlist; // <-- THE STRING
}
// other stuff...
@property (assign) NSString *str_CurrentPlist; // <-- THE STRING
@end
.m-file
Code:
#import "TableViewController.h"
@implementation TableViewController
@synthesize str_CurrentPlist; // <-- THE STRING
// other stuff...
@end
I'm using it to update the plist currently loaded into the Array Controller which is bound to and thus populates a TableView.
In my .m-file I have a function UpdateCurrentPlistString that updates that string and adds a number to it.
Starting-value is "MENU" (which will read "MENU.plist" when in a later function I use its value to load the plist), and pressing row 1 in my tableview will give the string "MENU_1", and so on.
Code:
- (void)UpdateCurrentPlistString:(NSInteger *)n_row
{
// IF: "MENU"
// -------------------
if ([self.str_CurrentPlist isEqualToString:@"MENU"])
{
// SET: Current Plist to "MENU_X"
self.str_CurrentPlist = [self.str_CurrentPlist stringByAppendingString:@"_"];
NSString *temp = [NSString stringWithFormat:@"%d", n_row];
self.str_CurrentPlist = [self.str_CurrentPlist stringByAppendingString:temp];
}
// ELSE : "MENU_X"
// ----------------------
else
{
// SET: Current Plist to "MENU_X_Y"
self.str_CurrentPlist = [self.str_CurrentPlist stringByAppendingString:@"_"];
NSString *temp = [NSString stringWithFormat:@"%d", n_row];
self.str_CurrentPlist = [self.str_CurrentPlist stringByAppendingString:temp];
}
}
This works fine the first time around, but the second time the function is called I receive the EXC_BAD_ACCESS-error.
Strangely enough, altering the code a little for debugging-purposes, this does NOT give any errors:
Code:
- (void)UpdateCurrentPlistString:(NSInteger *)n_row
{
// IF: "MENU"
// -------------------
if ([self.str_CurrentPlist isEqualToString:@"MENU"])
{
self.str_CurrentPlist = @"MENU_1";
}
// ELSE : "MENU_X"
// ----------------------
else
{
self.str_CurrentPlist = @"MENU_1_1";
}
}
This leads me to the conclusion that the problem might have to do with the way I concat the string with the row-number. Could it be that the format of the string is altered, or is there something more nefarious lurking inside this code?