Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

simaomm

macrumors newbie
Original poster
Dec 16, 2008
17
0
Hello,

I am trying to access some memory, belonging to an instance, from a class method.

That is, I am trying to access pdb, from doHistory.

I understand I can't do that, but how can I access pdb from doHistory? Is there any other way?

Thank you,
Simão

Code:
-(id) initWithDB: (BatMeasureDB*)pdb
{
	[super init];

	BatMeasureDB* pdb = [BatMeasureDB alloc] init];

	[NSThread detachNewThreadSelector:@selector(doHistory:withDB:) toTarget:[BatWatcher class] withObject:pdb];
	
	return self;
}


+(void) doHistory:(id)param withDB:(BatMeasureDB*)db
{
		[db toString];
}
 

simaomm

macrumors newbie
Original poster
Dec 16, 2008
17
0
make an accessor and call it on your instance db in doHistory:withDB?

-Lee

The problem is that I want to pass it as an argument when calling initWithDB.

The actual BatMeasureDB object belongs to another class.

But you are right, I was trying to simplify so I could explain.

Actually I have something like:

Code:
-(id) initWithDB: (BatMeasureDB*)pdb
{

	[super init];

	[NSThread detachNewThreadSelector:@selector(doHistory:withDB:) toTarget:[BatWatcher class] withObject:pdb];
	
	return self;
}

And

Code:
BatMeasureDB* pdb = [BatMeasureDB alloc] init];

Is executed before calling initWithDB.


I tried using:

Code:
	[NSThread detachNewThreadSelector:@selector(doHistory:withDB:) toTarget:self withObject:db];

So doHistory is now an object method and not a class method, but I still can't access the memory region pointed by (BatMeasureDB*)pdb inside doHistory.

Thank you for your reply,
SM
 

kpua

macrumors 6502
Jul 25, 2006
294
0
The selector you pass to detachNewThreadSelector:toTarget:withObject: may only have one argument (see the NSThread docs). That argument will be the "withObject:" object you passed in.

Your doHistory:withDB: selector has two arguments, and it looks like the first is completely unnecessary since you don't do anything with it. Try renaming it to doHistoryWithDB: and eliminate the first object.
 

simaomm

macrumors newbie
Original poster
Dec 16, 2008
17
0
The selector you pass to detachNewThreadSelector:toTarget:withObject: may only have one argument (see the NSThread docs). That argument will be the "withObject:" object you passed in.

Your doHistory:withDB: selector has two arguments, and it looks like the first is completely unnecessary since you don't do anything with it. Try renaming it to doHistoryWithDB: and eliminate the first object.

Thank you!

I didn't realize I left "param" there when I added withDB.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.