xcode 函数“...”的隐式声明在 C99 上无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17583497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:36:00  来源:igfitidea点击:

Implicit declaration of function '...' is invalid on C99

iosxcodedebuggingcompiler-errorssyntax-error

提问by George523

I am still working on an iPhone app called Cruzia and am now wondering why I am geting these two warnings, both in ViewController.m and three errors, all an Apple Mach-O Linker Error. If you can point me in the direction of some fixes I would be very appreciative. I have commented the warnings out below in a copy of my viewcontroller.m:

我仍在开发一款名为 Cruzia 的 iPhone 应用程序,现在想知道为什么我会在 ViewController.m 中收到这两个警告和三个错误,都是 Apple Mach-O 链接器错误。如果您能指出一些修复的方向,我将不胜感激。我在我的 viewcontroller.m 的副本中评论了下面的警告:

#import "CIAViewController.h"

@interface CIAViewController()


@end

@implementation CIAViewController




-(IBAction)press {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    cruzia.text = @"Play";
    textarea.text = @"Hello! You are playing the game of Cruzia!";

        // declare defaults it is not declared elsewhere within your view controller
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

        // The stringForKey method returns a String and not a Boolean value
        // However, if you just want to check if a value exists then it is implied you are checking for existence
        // If there is no value then it will return nil and statement will fail
        // You had "== YES" outside of the parenthesis which is an illegal statement
        if ([defaults stringForKey:kMusic])  {
            CFBundleRef mainBundle = CFBundleGetMainBundle();
            CFURLRef soundFileURLRef;
            soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click",                     CFSTR ("wav"), NULL);
            UInt32 soundID;
            AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
            AudioServicesPlaySystemSound(soundID); }

}


-(IBAction)press2 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    cruzia.text = @"Tutorial";
    textarea.text = @"Welcome! You are watching the Cruzia tutorial!";
    // declare defaults it is not declared elsewhere within your view controller
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    // The stringForKey method returns a String and not a Boolean value
    // However, if you just want to check if a value exists then it is implied you are checking for existence
    // If there is no value then it will return nil and statement will fail
    // You had "== YES" outside of the parenthesis which is an illegal statement
    if ([defaults stringForKey:kMusic])  {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click",                     CFSTR ("WAV"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID); }
}

-(IBAction)press3 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    cruzia.text = @"Options";
    textarea.text = @"Hello! You have clicked Options. Sadly, you need to open Settngs and go to the Cruzia area to get most of the options of the game.";
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click", CFSTR ("WAV"), NULL);
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
}

-(IBAction)press4 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 1;
    tutorialbtn.hidden = 1;
    optionsbtn.hidden = 1;
    trainingbtn.hidden = 1;
    back.hidden = 0;
    cruzia.text = @"Training";
    textarea.text = @"This is the training area. You can improve your Cruzia skills here!";
    // declare defaults it is not declared elsewhere within your view controller
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    // The stringForKey method returns a String and not a Boolean value
    // However, if you just want to check if a value exists then it is implied you are checking for existence
    // If there is no value then it will return nil and statement will fail
    // You had "== YES" outside of the parenthesis which is an illegal statement
    if ([defaults stringForKey:kMusic])  {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click",                     CFSTR ("WAV"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID); }
}

-(IBAction)press5 {
    cruzia.hidden = 0;
    textarea.hidden = 0;
    playbtn.hidden = 0;
    tutorialbtn.hidden = 0;
    optionsbtn.hidden = 0;
    trainingbtn.hidden = 0;
    back.hidden = 1;
    cruzia.text = @"Cruzia";
    textarea.text = @"";
    // declare defaults it is not declared elsewhere within your view controller
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    // The stringForKey method returns a String and not a Boolean value
    // However, if you just want to check if a value exists then it is implied you are checking for existence
    // If there is no value then it will return nil and statement will fail
    // You had "== YES" outside of the parenthesis which is an illegal statement
    if ([defaults stringForKey:kMusic])  {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"click",                     CFSTR ("WAV"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID); }

}

- (void)viewDidLoad
{
    textarea.hidden = 1;
    playbtn.hidden = 0;
    tutorialbtn.hidden = 0;
    optionsbtn.hidden = 0;
    trainingbtn.hidden = 0;
    back.hidden = 1;
    cruzia.text = @"Cruzia";
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateSettings:)
                                                name:
     NSUserDefaultsDidChangeNotification object:nil];

    [self setupDefaults];
}

- (void)viewDidUnload
{

    [super viewDidUnload];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidFinishLaunchingNotification object:nil];
}

-(void) setupDefaults {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];


    NSString *violenceValue = [defaults stringForKey:kViolenceMode];

    if ( violenceValue == nil ) {
        NSString *pathStr = [[NSBundle mainBundle] bundlePath];
        NSString *settingsBundlePath = [pathStr stringByAppendingPathComponent:@"Settings.bundle"];
        NSString *finalPath = [settingsBundlePath stringByAppendingPathComponent:@"Root.plist"];

        NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:finalPath];
        NSArray *prefSpecifierArray = [settingsDictionary objectForKey:@"PreferenceSpecifiers"];


        NSString *isMusicOn, *isSoundOn;

        NSDictionary *prefItem;

        for (prefItem in prefSpecifierArray) {
            NSString *keyValue = [prefItem objectForKey:@"Key"];
            id defaultValue = [prefItem objectForKey:@"DeafultValue"];

            if ([keyValue isEqualToString:kSound])
            {
                isSoundOn = defaultValue;
            }
            else if ([keyValue isEqualToString:kMusic])
            {
                isMusicOn = defaultValue;
            }

            NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:                                  isSoundOn, kSound, isMusicOn, kMusic, nil];

            [defaults registerDefaults:appDefaults];
            [defaults synchronize];

        }

    }

}



@end

And here is a link to a screenshot of the place I am getting the other errors with the Debug and Output panels open.

这是我在调试和输出面板打开时遇到其他错误的地方的屏幕截图链接。

enter image description here

在此处输入图片说明

Thanks again, -George

再次感谢,-乔治

回答by Michael Dautermann

As the build log says these two symbols are missing:

正如构建日志所说,缺少这两个符号:

AudioServicesCreateSystemSoundIDand AudioServicesPlaySystemSound

AudioServicesCreateSystemSoundIDAudioServicesPlaySystemSound

The simple solution is that it looks like you need to add the "AudioToolbox" framework to your project.

简单的解决方案是,您似乎需要将“AudioToolbox”框架添加到您的项目中。