Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何通过NSThread传递参数_Objective C_Multithreading - Fatal编程技术网

Objective c 如何通过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

我以前从未使用过NSThread,我想知道是否可以将参数传递给它,如果可以,如何传递?例如:

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];
}