현재 C에서 Objective-C로 이동 중이며,이 코드는 모두 멋쟁이 같지만 Xcode는 그렇지 않다고 생각합니다. 나는 인터넷에서이 코드 샘플을 얻고 끊임없이 그것을 해결하기 위해 노력하고 나는 데드 엔드에 왔어요 :이 단순한 Objective-C 코드는 정확히 무엇이 잘못 되었습니까?
#include <objc/Object.h>
@interface Greeter:Object
{
/* This is left empty on purpose:
** Normally instance variables would be declared here,
** but these are not used in our example.
*/
}
- (void)greet;
@end
#include <stdio.h>
@implementation Greeter
- (void)greet
{
printf("Hello, World!\n");
}
@end
#include <stdlib.h>
int main(void)
{
id myGreeter;
myGreeter = [Greeter new];
[myGreeter greet];
[myGreeter release];
return 0;
}
오류가 myGreeter = [Greeter new];
줄 것으로 보인다와 엑스 코드에 대한 무언가로 문제를 분리 스레드 1. alloc/init이 필요합니까?
[Switching to process 1833 thread 0x0]
2011-04-18 21:52:10.323 PROJ[1833:903] *** NSInvocation: warning: object 0x100001160 of class 'Greeter' does not implement methodSignatureForSelector: -- trouble ahead
2011-04-18 21:52:10.326 PROJ[1833:903] *** NSInvocation: warning: object 0x100001160 of class 'Greeter' does not implement doesNotRecognizeSelector: -- abort
sharedlibrary apply-load-rules all
Current language: auto; currently objective-c
(gdb)
저는 전문가가 아니지만 왜 Greeter myGreeter = [Greeter new]입니까? 나는 "id"가 당신의 방법에 대해 알게 될 것이라고 믿지 않습니다. 비록 당신이 그것에 인사를 할 수 있다고해도 말입니다. – Marvo
'new'와'alloc-init'은 같은 의미로 사용할 수 있습니다. Xcode가 말하는 콘솔 로그를 게시 할 수 있습니까? –
@Marvo 괜찮을 것입니다. 경고를 주면 항상 그렇게하고 성가 시게하기 때문에 ID의 메소드를 호출 할 때 경고를 얻지 못합니다. 런타임에 객체가 무엇인지 파악하고 메소드를 찾는다. – Nektarios