如何通过 NSThread 传递参数
我以前从未使用过 NSThread,我想知道是否可以向其中传递参数,如果可以,如何传递?例如:
NSObject *phrase = @"I JUST MADE IT THROUGH TO THE THREAD METHOD!";
[NSThread detachNewThreadSelector:@selector (run_thread)
toTarget:self
withObject:phrase];
那么
-(void)run_thread
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"RECORD FILE PATH ----> %@", phrase);
[pool drain];
}
我想你明白我正在尝试做什么。有什么建议吗?
I've never used NSThread before and I was wondering if it was possible to pass arguments into it and if so, how? For example:
NSObject *phrase = @"I JUST MADE IT THROUGH TO THE THREAD METHOD!";
[NSThread detachNewThreadSelector:@selector (run_thread)
toTarget:self
withObject:phrase];
then
-(void)run_thread
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"RECORD FILE PATH ----> %@", phrase);
[pool drain];
}
I think you see what I'm trying to do. Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你就快到了:
You're almost there: