Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

SIGABRT error when clicking a switch on the IOS simulator

Hi! I have been working on an iPhone app Cruzia and was wondering if anyone knows why I am getting this SIGABRT error in the simulator whenever I click one of the switches in the options menu of my game. Here is my 15 main file with the error commented off.

#import <UIKit/UIKit.h>

#import "CIAAppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([CIAAppDelegate class]));
//Thread 1: signal SIGABRT
    }
}

For reference, here is my ViewController.m

#import "CIAViewController.h"

@interface CIAViewController()


@end

@implementation CIAViewController



-(IBAction)press {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    soundlbl.hidden = 1;
    music.hidden = 1;
    sound.hidden = 1;
    musiclbl.hidden = 1;
    cruzia.text = @"Play";
    textarea.text = @"Hello! You are playing the game of Cruzia!";
        if (clicked == 1)  {
                CFBundleRef mainBundle = CFBundleGetMainBundle();
                CFURLRef soundFileURLRef;
                soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click",                     CFSTR ("electronic click.wav"), NULL);
                UInt32 soundID;
                AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
                AudioServicesPlaySystemSound(soundID);
             }
}


-(IBAction)press2 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    soundlbl.hidden = 1;
    music.hidden = 1;
    sound.hidden = 1;
    musiclbl.hidden = 1;
    cruzia.text = @"Tutorial";
    textarea.text = @"Welcome! You are watching the Cruzia tutorial!";
    if (clicked == 1)  {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click",                     CFSTR ("electronic click.wav"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
    }
}

-(IBAction)press3 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    soundlbl.hidden = 0;
    music.hidden = 0;
    sound.hidden = 0;
    musiclbl.hidden = 0;
    cruzia.text = @"Options";
    textarea.text = @"Hello! You have clicked Options. To control other areas of the gane, go to the settings app and open the Cruzia addon.";
    if (clicked == 1)  {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click",                     CFSTR ("electronic click.wav"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
    }
}

-(IBAction)press4 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    soundlbl.hidden = 1;
    music.hidden = 1;
    sound.hidden = 1;
    musiclbl.hidden = 1;
    cruzia.text = @"Training";
    textarea.text = @"This is the training area. You can improve your Cruzia skills here!";
    if (clicked == 1)  {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click",                     CFSTR ("electronic click.wav"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
    }
}

-(IBAction)returnpress
    {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 0;
    tutorialbtn.hidden = 0;
    optionsbtn.hidden = 0;
    trainingbtn.hidden = 0;
    back.hidden = 1;
    soundlbl.hidden = 1;
    music.hidden = 1;
    sound.hidden = 1;
    musiclbl.hidden = 1;
    cruzia.text = @"Cruzia";
    textarea.text = @"";
    if (clicked == 1)  {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click",                     CFSTR ("electronic click.wav"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
    }

}

- (void)viewDidLoad
{
    textarea.hidden = 1;
    playbtn.hidden = 0;
    tutorialbtn.hidden = 0;
    optionsbtn.hidden = 0;
    trainingbtn.hidden = 0;
    back.hidden = 1;
    soundlbl.hidden = 1;
    music.hidden = 1;
    sound.hidden = 1;
    musiclbl.hidden = 1;
    cruzia.text = @"Cruzia";
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateSettings:)
                                                name:
     NSUserDefaultsDidChangeNotification object:nil];

    [self setupDefaults];
}

- (void)viewDidUnload
{

    [super viewDidUnload];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidFinishLaunchingNotification object:nil];
}

-(void) setupDefaults {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];


    NSString *violenceValue = [defaults stringForKey:kViolenceMode];

    if ( violenceValue == nil ) {
        NSString *pathStr = [[NSBundle mainBundle] bundlePath];
        NSString *settingsBundlePath = [pathStr stringByAppendingPathComponent:@"Settings.bundle"];
        NSString *finalPath = [settingsBundlePath stringByAppendingPathComponent:@"Root.plist"];

        NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:finalPath];
        NSArray *prefSpecifierArray = [settingsDictionary objectForKey:@"PreferenceSpecifiers"];


        NSString *violence_identifier, *isPushNotifyOn;

        NSDictionary *prefItem;

        for (prefItem in prefSpecifierArray) {
            NSString *keyValue = [prefItem objectForKey:@"Key"];
            id defaultValue = [prefItem objectForKey:@"DeafultValue"];

            if ([keyValue isEqualToString:kViolenceMode])
            {
                violence_identifier = defaultValue;
            }
            else if ([keyValue isEqualToString:kPushNotifications])
            {
                isPushNotifyOn = defaultValue;
            }

            NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:                                  violence_identifier, kViolenceMode, isPushNotifyOn, kPushNotifications, nil];

            [defaults registerDefaults:appDefaults];
            [defaults synchronize];

        }

    }

}



@end

And here is my .h:

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>


int clicked;

#define kViolenceMode @"violence_identifier"
#define kPushNotifications @"isPushNotifyOn"

@interface CIAViewController : UIViewController {

    IBOutlet UILabel *cruzia;
    IBOutlet UILabel *textarea;
    IBOutlet UIButton *playbtn;
    IBOutlet UIButton *tutorialbtn;
    IBOutlet UIButton *optionsbtn;
    IBOutlet UIButton *trainingbtn;
    IBOutlet UIButton *back;
    IBOutlet UISwitch *music;
    IBOutlet UISwitch *sound;
    IBOutlet UILabel *soundlbl;
    IBOutlet UILabel *musiclbl;
}

- (void) setupDefaults;

-(IBAction)press;
-(IBAction)press2;
-(IBAction)press3;
-(IBAction)press4;
-(IBAction)returnpress;
-(IBAction)music;
-(IBAction)sound;
@end

If anyone knows why I am getting this error, I would greatly appreciate it if they could tell me. Thanks again, -Raph

PS: If anyone can help I would be very happy as I posted this 7 hours ago! Thanks!

1 Answer

Go to your storyboard or xib, right click on files owner and see if there are any warnings on the screen that causes the app to crash. You need to actually manually check for these, for some reason XCode doesn't alert you to them. This is usually why I get a sigbart error. What it means is you connected up an IBOutlet or IBAction, then deleted in in .h and .m but forgot to delete the connection in the storyboard/xib

Thanks but there were no warnings there. PS. This was the cause of a previous sigbart error so thanks for reminding me to try. I tried twice and ran my app again but it made no difference. Also, Files Owner is now called View Controller.