Reputation: 61
I'm reading this programming book with the following code
#import "Fraction.h"
int main (int argc, char * argv [])
{
@autoreleasepool {
Fraction *f = [[Fraction alloc] init];
[f noSuchMethod];
NSLog (@"Execution continues!");
}
return 0;
}
Apparently it's supposed to give me the following output:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Fraction noSuchMethod]: unrecognized selector sent to instance 0x103f00' * Call stack at first throw:'')
Instead I just get an error that says: No visible @interface for 'Fraction' declares the selector 'noSuchMethod'
Is this because I have a newer version of xcode, or am I doing something wrong? It seems pretty straight forward to me.
Edit:
Also... Would this following code work in the newest version of xcode?
int main (int argc, char * argv [])
{
@autoreleasepool {
Fraction *f = [[Fraction alloc] init];
@try {
[f noSuchMethod];
}
@catch (NSException *exception) {
NSLog(@"Caught %@%@", [exception name], [exception reason]);
}
NSLog (@"Execution continues!");
}
return 0;
}
Edit #2:
Upvotes: 0
Views: 116
Reputation: 6852
Xcode doesn't let you compile if you call a method that certainly doesn't exist.
Else use the performSelector:
method.
EDIT
If you directly call the method it won't compile, like in the initial question you have asked.
If you still want to call this method for some reason, because maybe it's private or something else, you can call it via performSelector:.
It will still tell you that the object might not respond to it. You can suppress the warning, as you can see here:
http://www.stackoverflow.com/a/7933931/1320374
Upvotes: 2