Ok for some reason my code wont play nice and I’m too new to cocoa to figure this out on my own..
when the send button is pressed it is meant to run the createEmail method. But it says
GDB: Program received signal: “EXC_BAD_ACCESS”. when the button is pressed.
#import "Controller.h"
@implementation Controller
-(IBAction)send:(id)sender{
[self createEmail];
}
-(void)createEmail{
NSString *number = [numfield stringValue];
NSString *carrier = [carrierfield stringValue];
NSString *carrierTag;
[carrier lowercaseString]; //make all lowercase
//set carrierTag based on what carrier it is
if ([carrier isEqualToString:@"verizon"]) {
carrierTag = @"@vtext.com";
}
if ([carrier isEqualToString:@"at&t"]) {
carrierTag = @"@txt.att.net";
}
if ([carrier isEqualToString:@"nextel"]) {
carrierTag = @"@messaging.nextel.com";
}
if ([carrier isEqualToString:@"sprint"]) {
carrierTag = @"@messaging.sprintpcs.com";
}
if ([carrier isEqualToString:@"cingular"]) {
carrierTag = @"@cingularme.com";
}
if ([carrier isEqualToString:@"cingular"]) {
carrierTag = @"@cingularme.com";
}
if ([carrier isEqualToString:@"virgin"]) {
carrierTag = @"@vmobl.com";
}
if ([carrier isEqualToString:@"t-mobile"]) {
carrierTag = @"@tmomail.net";
}
//Concatenate number and carrierTag to create an email address
email = [number stringByAppendingString:carrierTag];
}
@end
Well, I see two possibilities. Either
carrieris not set correctly or it’s not equal to any of those strings in which casecarrierTagis left uninitialised.In the former case, the exception is probably on the line:
In the latter, it will probably be at:
The debugger should provide you with that information, and you should provide it to us as well 🙂
In addition,
lowercaseStringreturns another string, it doesn’t operate in-place, so you need:What you may want to do is set
carrierTagto an initially empty string so that nothing is appended if there is no match: