如何在Objective C中解决警告隐式声明函数

RAG*_*poR 11 iphone objective-c

日志

warning: implicit declaration of function 'TutorialAlertWithMessageAndDelegate'
Run Code Online (Sandbox Code Playgroud)

我的代码

.h

void TutorialAlertWithMessageAndDelegate(NSString *title, NSString *message, id delegate);


.m
void TutorialAlertWithMessageAndDelegate(NSString *title, NSString *message, id delegate)
{
    /* open an alert with OK and Cancel buttons */
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title 
                                                    message:message
                                                   delegate:delegate 
                                          cancelButtonTitle:@"Dismiss"
                                          otherButtonTitles: @"Show Tutorial", @"Disable Tutorial", nil];
    // otherButtonTitles: @"Show Next Tip", @"Disable Tips", nil];
    [alert show];
    [alert release];
}
Run Code Online (Sandbox Code Playgroud)

ben*_*ado 12

当您在声明函数之前尝试调用函数时会生成该警告.标题(.h)文件中的声明似乎是正确的,但您可能不会在调用该函数的源文件中包含该头文件.一定要把:

#include "Tutorial.h" // replace with actual filename, of course
Run Code Online (Sandbox Code Playgroud)

在该源文件的顶部.

  • C不要求您声明函数,尽管这样做是最佳实践.这就是为什么它只给你一个警告而不是错误. (5认同)