Objective c 如何通过NSThread传递参数
我以前从未使用过NSThread,我想知道是否可以将参数传递给它,如果可以,如何传递?例如:Objective c 如何通过NSThread传递参数,objective-c,multithreading,Objective C,Multithreading,我以前从未使用过NSThread,我想知道是否可以将参数传递给它,如果可以,如何传递?例如: NSObject *phrase = @"I JUST MADE IT THROUGH TO THE THREAD METHOD!"; [NSThread detachNewThreadSelector:@selector (run_thread) toTarget:self withObject:ph
NSObject *phrase = @"I JUST MADE IT THROUGH TO THE THREAD METHOD!";
[NSThread detachNewThreadSelector:@selector (run_thread)
toTarget:self
withObject:phrase];
然后
我想你明白我想做什么了。有什么建议吗?你就快到了:
NSObject *phrase = @"I JUST MADE IT THROUGH TO THE THREAD METHOD!";
[NSThread detachNewThreadSelector:@selector (run_thread:) // have to add colon
toTarget:self
withObject:phrase];
-(void)run_thread:(NSObject* )phrase // change method signature to support taking an NSObject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"RECORD FILE PATH ----> %@", phrase);
[pool drain];
}
NSObject *phrase = @"I JUST MADE IT THROUGH TO THE THREAD METHOD!";
[NSThread detachNewThreadSelector:@selector (run_thread:) // have to add colon
toTarget:self
withObject:phrase];
-(void)run_thread:(NSObject* )phrase // change method signature to support taking an NSObject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"RECORD FILE PATH ----> %@", phrase);
[pool drain];
}
[NSThread detachNewThreadSelector:@selector(run_thread:)
toTarget:self
withObject:phrase];
-(void)run_thread:(NSString *)phrase
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"RECORD FILE PATH ----> %@", phrase);
[pool drain];
}