Я новичок в Objective C, и я пытался создать образец программы самостоятельно. Когда я скомпилировал код на своей машине Linux, я получил достаточное количество предупреждений и был скомпилирован. Но удивительно, что у меня нет выхода, вместо этого у меня появилось много сообщений. Описание код был приведен нижеObjective C Класс может не отвечать на methord
Метод Декларация
@interface AsciitoBinaryClass:NSObject
/* method declaration */
- (int)AsciitoBinary: (char)d Num1:(int*)bin ;
@end
Метод
@implementation AsciitoBinaryClass
/* method Convert Ascii to Binary */
- (int)AsciitoBinary: (char)d Num1:(int*)bin{
int len=0;
int a=d;
while(a>0)
{
bin[len]=a%2;
a/=2;
len++;
}
return len;
}
@end
Метод вызова от Main
AsciitoBinaryClass *asciitobinaryClass = [[AsciitoBinaryClass alloc]init];
len = [asciitobinaryClass AsciitoBinary:a Num2:bin];
Компиляционном предупреждения приведены ниже
[email protected]:~/study/c/crypt/objc$ gcc test.m -o test `gnustep-config --objc-flags` `gnustep-config --base-libs`
test.m: In function ‘main’:
test.m:35:2: warning: ‘AsciitoBinaryClass’ may not respond to ‘-AsciitoBinary:Num2:’
len = [asciitobinaryClass AsciitoBinary:a Num2:bin];
^
test.m:35:2: warning: (Messages without a matching method signature
test.m:35:2: warning: will be assumed to return ‘id’ and accept
test.m:35:2: warning: ‘...’ as arguments.)
test.m:35:6: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
len = [asciitobinaryClass AsciitoBinary:a Num2:bin];
^
test.m:32:13: warning: variable ‘len’ set but not used [-Wunused-but-set-variable]
int bin[8],len=0;
сообщений, во время выполнения
[email protected]:~/study/c/crypt/objc$ ./test
2016-05-03 15:25:02.600 test[22624] autorelease called without pool for object (0x2607270) of class GSCInlineString in thread <NSThread: 0x2593270>
2016-05-03 15:25:02.616 test[22624] autorelease called without pool for object (0x2745330) of class NSException in thread <NSThread: 0x2593270>
2016-05-03 15:25:02.616 test[22624] autorelease called without pool for object (0x2744530) of class NSLongLongNumber in thread <NSThread: 0x2593270>
2016-05-03 15:25:02.616 test[22624] autorelease called without pool for object (0x2735790) of class NSLongLongNumber in thread <NSThread: 0x2593270>
2016-05-03 15:25:02.617 test[22624] autorelease called without pool for object (0x2732dc0) of class NSLongLongNumber in thread <NSThread: 0x2593270>
2016-05-03 15:25:02.617 test[22624] autorelease called without pool for object (0x2734260) of class NSLongLongNumber in thread <NSThread: 0x2593270>
2016-05-03 15:25:02.617 test[22624] autorelease called without pool for object (0x26ae280) of class NSLongLongNumber in thread <NSThread: 0x2593270>
2016-05-03 15:25:02.617 test[22624] autorelease called without pool for object (0x264c610) of class NSIntNumber in thread <NSThread: 0x2593270>
2016-05-03 15:25:02.617 test[22624] autorelease called without pool for object (0x2653490) of class NSLongLongNumber in thread <NSThread: 0x2593270>
2016-05-03 15:25:02.617 test[22624] autorelease called without pool for object (0x264af40) of class NSIntNumber in thread <NSThread: 0x2593270>
./test: Uncaught exception NSInvalidArgumentException, reason: -[AsciitoBinaryClass AsciitoBinary:Num2:]: unrecognized selector sent to instance 0x2598520
[email protected]:~/study/c/crypt/objc$
Я уже протестировали эту программу, я написанный на C и это делает хорошо без каких-либо проблем ... – Shameerariff
Не спам-теги! C, C++ и ObjC - все разные языки (за одним исключением, что здесь не имеет значения). – Olaf
Поскольку Obj C получен из C и C++, я добавил C и C++ в тег. – Shameerariff