如何修复此警告:“未找到方法(返回类型默认为'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
或任何*
),特别是当它没有相同的大小时,你会发现很奇怪而且很难找到错误。
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屋!