【问题标题】:Implicit declaration of function '...' is invalid on C99函数“...”的隐式声明在 C99 上无效
【发布时间】:2013-07-09 03:24:03
【问题描述】:

我仍在开发一款名为 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

这里是一个链接,指向打开调试和输出面板时出现其他错误的位置。

再次感谢, -乔治

【问题讨论】:

    标签: ios xcode debugging compiler-errors syntax-error


    【解决方案1】:

    正如构建日志所说,这两个符号丢失了:

    AudioServicesCreateSystemSoundIDAudioServicesPlaySystemSound

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

    【讨论】:

    • 一点都不傻,也不要心疼。有时你只需要另一双眼睛来看待问题,一切都会变得清晰。
    • 我已经添加了它,但仍然无法构建。在另一个项目中,这是一个警告,可以构建正常,但在一个新项目中,这是一个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 2018-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多