user275951
user275951

Reputation:

Newbie question: NSOperation for iphone SDK

Hi I got some problem with NSOperation . I always got error at self = [super init]; (already use break point to find this) it always return "Program received signal: EXC_BAD_ACCESS" all the time

//AddThread.h
@interface AddThread : NSOperation
{
    NSString * str;
}
@property (nonatomic,retain) NSString * str;
-(id) initWithString:(NSString *) tmpStr;
@end

and for .m

//AddThread.m
#import "AddThread.h"
@implementation AddThread
@synthesize str;
- (id) initWithString:(NSString *)tmpStr
{
    self = [super init];
    if (self != nil)
    {
        self.str = tmpStr;
    }
    //NSLog(self);
    //[super init];
        return self;
}
- (void) main
{
    NSLog(self.str);
}
- (void) dealloc{
    [str release];
    str = nil;
    [super dealloc];
}
@end

well I stuck with this for while and if possible any resources ,articles things for basic example of NSoperation?

Upvotes: 0

Views: 511

Answers (1)

Jasarien
Jasarien

Reputation: 58478

In your main method, you are calling NSLog(self.str) - While this will work if the object you pass in is a string, it won't work if you continue to try and log other objects. NSLog takes a format string as a parameter. If you just do NSLog(self) like you are in some of your commented code, and self is not a string, it'll crash because it expected a string. You should do NSLog(@"self: %@", self) the %@ will print out the string returned by an objects description method.

Other than that, your init method looks fine, how exactly are you creating an instance of this object? Could you show the code for that? The problem may lie there.

Upvotes: 1

Related Questions