我正在使用以下代码阅读这本编程书
#import "Fraction.h"
int main (int argc, char * argv [])
{
@autoreleasepool {
Fraction *f = [[Fraction alloc] init];
[f noSuchMethod];
NSLog (@"Execution continues!");
}
return 0;
}
显然它应该给我以下输出:
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[Fraction noSuchMethod]:无法识别的选择器发送到实例 0x103f00”*第一次抛出调用堆栈:“”)
相反,我只是收到一条错误消息:No visible @interface for 'Fraction' declarations the selector 'noSuchMethod'
这是因为我有更新版本的 xcode,还是我做错了什么?这对我来说似乎很简单。
编辑:
另外......下面的代码可以在最新版本的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;
}
编辑#2: