问题描述
我仍然在使用一个名为Cruzia的iPhone应用程序,现在想知道为什么我会在ViewController.m和三个错误中发出这两个警告,所有这一切都是Apple Mach-O链接器错误。如果你能指出我的一些修复方向,我将非常感激。我已经在我的viewcontroller.m的副本中发表了以下警告: #importCIAViewController.h
@interface CIAViewController()
@end
@implementation CIAViewController
- (IBAction)按{
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 = @你好!你正在玩Cruzia的游戏!
//声明默认值在声明控制器的其他地方未声明
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
// stringForKey方法返回一个String而不是一个布尔值
//但是,如果您只想检查一个值是否存在,则表示您正在检查存在
//如果没有值,那么它将返回nil,并且语句将失败
//您在括号内的== YES是非法语句
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 = @教程;
textarea.text = @欢迎!您正在观看Cruzia教程!;
//声明默认值未在视图控制器的其他位置声明
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
// stringForKey方法返回一个String而不是一个布尔值
//但是,如果您只想检查一个值是否存在,则表示您正在检查存在
//如果没有值,那么它将返回nil,并且语句将失败
//您在括号内的== YES是非法语句
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 = @选项;
textarea.text = @您好!您点击了选项,可悲的是,您需要打开Settngs并转到Cruzia区才能获得大部分游戏选项。
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle,(CFStringRef)@click,CFSTR(WAV),NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef,& soundID);
MusicServicesPlaySystemSound(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 = @培训;
textarea.text = @这是训练区,你可以在这里提高你的Cruzia技能!
//声明默认值未在视图控制器的其他位置声明
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
// stringForKey方法返回一个String而不是一个布尔值
//但是,如果您只想检查一个值是否存在,则表示您正在检查存在
//如果没有值,那么它将返回nil,并且语句将失败
//您在括号内的== YES是非法语句
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 = @;
//声明默认值未在视图控制器的其他位置声明
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
// stringForKey方法返回一个String而不是一个布尔值
//但是,如果您只想检查一个值是否存在,则表示您正在检查存在
//如果没有值,那么它将返回nil,并且语句将失败
//您在括号内的== YES是非法语句
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对象:nil];
[self setupDefaults];
}
- (void)viewDidUnload
{
[super viewDidUnload];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidFinishLaunchingNotification对象: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];
[默认同步];
}
}
}
@end
这里是一个链接,我打开了Debug和Output面板的其他错误的地方的屏幕截图。 / p>
再次感谢
-George
缺少符号:
和
简单的解决方案是,您需要将AudioToolbox框架添加到您的项目中。
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:
#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.
Thanks again,-George
As the build log says these two symbols are missing:
AudioServicesCreateSystemSoundIDand AudioServicesPlaySystemSound
The simple solution is that it looks like you need to add the "AudioToolbox" framework to your project.
这篇关于函数“...”的隐式声明在C99中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!