如何修复此警告:“找不到方法(返回类型默认为 'id')" [英] How do I fix this warning: "Method not found (return type defaults to 'id')"
问题描述
我正在尝试从我的 iPhone 应用程序中删除其中一些警告.我得到最多的是当我有一个 void 函数并使用 [self myFunction]; 调用它时.警告在我调用函数的那一行,它说:找不到方法'-myFunction'(返回类型默认为'id')."我需要做什么来解决这个问题?谢谢
I am trying to get rid of some of these warnings from my iPhone application. The one I get the most is when I have a void function and I call it using [self myFunction];. The warning is on the line where I call the function and it says: "Method '-myFunction' not found (return type defaults to 'id')." What do I need to do to fix this? Thanks
推荐答案
在你的头文件中声明函数,像这样:
Declare the function in your header file, like so:
-(void)myFunction;
或
-(NSString*)myFunction;
-(id)myFunction;
-(NSInteger)myFunction;
-(BOOL)myFunction;
等等等等
这比仅仅让编译器静音更重要:如果函数的返回类型不是指针(id
或 anything*
),尤其是当它不'没有相同的大小,你可能会变得非常奇怪并且很难找到错误.
This is of more importance than just silencing the compiler: if the return type of a function is not a pointer (id
or anything*
), especially when it doesn't have the same size, you can get really odd and hard to find bugs.
例如如果一个函数返回一个 CGRect
结构,并且编译器假定 id
(如警告所说),就会发生非常奇怪的事情.
E.g. if a function returns a CGRect
struct, and the compiler assumes id
(as the warning says), really weird things will happen.
这篇关于如何修复此警告:“找不到方法(返回类型默认为 'id')"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!