Prasad G
Prasad G

Reputation: 6718

Thread1: Program received signal: "SIGBRT"

The project builds fine, but once the app tries to run it crashes with this:

It(the error) has been shown like this.

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
                    // here i got Thread1: Program received signal: "SIGBRT" 
    }
}

My code is:

(i)

(I have declared collecter instance and import the collector.h)

#import <UIKit/UIKit.h>
#import "Collector.h"

@interface ViewController : UIViewController{
    Collector *model;
    IBOutlet UILabel *totalStrings;
    IBOutlet UILabel *totalNumbers;
}

-(void)collect:(UIButton *)sender;

@end

(ii)

#import "ViewController.h"
#import "Collector.h"

@implementation ViewController

-(void)updateUI
{
    totalNumbers.text = [NSString stringWithFormat:@"%d",model.totalNumberCount];
    totalStrings.text = [NSString stringWithFormat:@"%d",model.totalStringCount];
}

-(IBAction)collect:(UIButton *)sender
{
    if(!model) model = [[Collector alloc] init];
    double doubleValue = [sender.titleLabel.text doubleValue];
    if (doubleValue) {
        [model collect:[NSNumber numberWithDouble:doubleValue]];
    } else{
        [model collect:sender.titleLabel.text];
    }
    [self updateUI];
}

@end

(iii)

#import <Foundation/Foundation.h>

@interface Collector : NSObject{
    NSMutableDictionary *counts;

}
-(void)collect:(id)anObject;
@property (readonly) int totalStringCount;
@property (readonly) int totalNumberCount;

@end

(iv)

#import "Collector.h"

@interface Collector()

@property (readonly) NSMutableDictionary *counts;
@end

@implementation Collector

-(NSMutableDictionary *)counts
{
    if (!counts) {
        counts = [[NSMutableDictionary alloc] init];
    }
    return counts; 
}

-(void)collect:(id)anObject
{
    if ([anObject isKindOfClass:[NSString class]] || [anObject isKindOfClass:[NSNumber class]] ) {
        NSNumber *existingCount = [self.counts objectForKey:anObject];
        [self.counts setObject:[NSNumber numberWithInt: [existingCount intValue] + 1] forKey:anObject];

    }
}

- (int) totalStringCount
{
    int total = 0;
    for (id key in self.counts) {
        if ([key isKindOfClass:[NSString class]]) {
            total +=[[self.counts objectForKey:key] intValue];
        }
    }
    return total;
}

-(int)totalNumberCount
{
    int total = 0;
    for (id key in self.counts) {
        if ([key isKindOfClass:[NSNumber class]]) {
            total +=[[self.counts objectForKey:key] intValue];
        }
    }
    return total;
}

@end

What do you think is causing this problem?

Upvotes: 1

Views: 796

Answers (1)

Niko
Niko

Reputation: 2543

Check on this post how to set NSZombieEnabled. That will show more details on crashes that should help you debug your issue :

App crash only on iPhone Device and not in Simulator

Upvotes: 1

Related Questions