以下代码按预期编译和执行。
#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. ......
我错了什么?如何避免警告/运行时错误。