开发者

Objective-C Model class + method = SIGABRT

I know this is pretty basic, but I can't figure it out.

I've got a basic model class (for simplicity i'll leave just some properties)

@interface Marker : NSObject {
    NSInteger book_id;
    NSString *detail;
    NSNumber *lat;   
}

@property (nonatomic, assign) NSInteger book_id;
@property (nonatomic, retain) NSNumber *lat;
@property (nonatomic, retain) NSString *detail;

@end

@synthesize book_id, detail, lat;

- (id)init
{
    self = [super init];
    if (self) {
        detail = [NSString alloc];
        lat = [NSNumber alloc];
    }

    return self;
}

- (void) dealloc {
    [detail release];
    [lat release];
    [super dealloc];
}

@end

and I've got a singleton with simple method, I want to push instances of this class into that singletons array, i've got it like this

#import "Marker.h"

@interface MarkersSingleton : NSObject {
    NSMutableArray *markers;
}

+ (MarkersSingleton *)getInstance;
- (void)addMarker: (Marker *) marker;

@property (nonatomic, retain) NSMutableArray *markers;

@end

#import "MarkersSingleton.h"

@implementation MarkersSingleton

@synthesize markers;

- (id) init{
    self = [super init];

    if(self){
        markers = [[NSMutableArray alloc] 开发者_如何转开发init];
    }

    return self;
}

+ (MarkersSingleton *) getInstance {
    static dispatch_once_t pred;
    static MarkersSingleton *inst;
    dispatch_once(&pred, ^{
        inst = [[MarkersSingleton alloc] init];
    });

    return inst;
}

- (void) addMaker: (Marker *) marker {
    [markers insertObject:marker atIndex:[markers count]];
}

- (void) dealloc {
    [markers release];
    [super dealloc];
}

@end

and now when I try

Marker *marker = [[Marker alloc] init];

...some sets...

[[MarkersSingleton getInstance] addMarker:marker];

I get the "Program received signal: SIGABRT". I also tried [marker copy] but I guess I'm missing a copy implementation for my class, should I implement the copy and then copy the marker before using addMarker or is there any other better way?

Thanks.


In addition to the points in the comment thread above, where you do not initialize your variables properly, one guess would be that, in the code you showed us, you have misspelled the method addMarker: as addMaker:.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜