0

以下代码按预期编译和执行。

#import <objc/objc.h>
#import <Foundation/Foundation.h>

BOOL loopValue = YES;
@interface myThread:NSObject
-(void) enterThread: (NSArray *) elemt count: (NSString *) x;
@end

@implementation myThread
-(void) enterThread : (NSArray *) elemt
{
  NSLog (@" Inside mythread ");
  NSAutoreleasePool *pool =  [[ NSAutoreleasePool alloc] init];
 int i;
int cnt =10;
  for(i=0; i<cnt; i++) {
  NSLog (@"Number of elemennts in array %i ", [elemt count]); 
  [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
  }

  loopValue = NO; 
  [pool drain];  
}
@end



int main ( int argc, char ** argv)
{
  NSAutoreleasePool *pool = [[ NSAutoreleasePool alloc] init];
  // id tobj = [[myThread alloc] init];
  id tobj = [ myThread new ];
  NSLog (@"Starting New Thread ");
   [NSThread detachNewThreadSelector:@selector(enterThread:)  toTarget:tobj withObject:[NSArray arrayWithObjects:@"ram",@"20",nil]];
  while(1)
  if ( loopValue )
    [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
   else
      break;


  NSLog (@".. Exiting.. \n");
  [pool drain];
  return 0; 

}

我的问题:

在编译时,我确实收到以下警告..

mythread.m:24:1: warning: incomplete implementation of class ‘myThread’ [enabled by default]

mythread.m:24:1:警告:'-enterThread:count:' 的方法定义未找到 [默认启用]

执行时

WARNING your program is becoming multi-threaded, but you are using an ObjectiveC runtime library .... Removed due to redability]hich does not have a thread-safe implementation of the +initialize method. ......

我错了什么?如何避免警告/运行时错误。

4

1 回答 1

1

你声明的方法是enterThread:count:,但你实现的方法是enterThread:。此外,您收到的警告,我敢肯定我只是从旧的 GNUstep 运行时中看到的……但我想没有。

于 2012-04-14T12:58:36.307 回答