interface 'NSObject' is not a successor of 'MyClass'
Hi All,
Just learning Objective C. AppCode is sweet.
I'm looking at an example of how to create a constructor from here:
http://www.roseindia.net/iphone/objectivec/constructors.shtml
When I use this I see a warning (code intention yellow bar) on this line:
self = [super init];
which says interface 'NSObject' is not a successor of 'MyClass'.
Any idea what this means? Is there something wrong with the sample code?
TIA
请先登录再写评论。
Hi!
First of all, I'm not sure wether you choose an iPhone application or a Mac application as your project template. Next, I don't think this is an bug of something like that in AppCode.
Let's step through the RoseIndia example:
1) Create a new Cocoa Application project
2) Create a new class MyClass
3) Paste in the example code from the RoseIndia website
4) Put the main() example code in applicationDidFinishLoading method in your AppDelegate. Like this:
5) Add 'return nil' to the end of the set:(int)x-method in MyClass.m
6) Organize / optimize your imports (Ctrl Alt - O)
7) Build and run your application.
The result will be "Sum is: 22".
So, in short: your error was due to example code. Copy and paste wasn't sufficient in this case.
Best regards,
Rutger
Ok that's cool. I did all that. But MyClass still shows the warning "interface 'NSObject' is not a successor of 'MyClass'". I don't understand what this warning means.
I guess I found the the fix, change your line to:
Now it works. The compiler needs to know on which class it should perform the init (as far as I understand).
A full and detailled explanation is found at http://cocoawithlove.com/2009/04/what-does-it-mean-when-you-assign-super.html
Good luck!
Thanks!