XCode- 需要帮助解决错误(预期;和预期声明) [英] XCode- Need Help With Errors (Expected ; and Expected Statement)

查看:43
本文介绍了XCode- 需要帮助解决错误(预期;和预期声明)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.m 编码:

-(void)viewDidLoad {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"MathMusic2" ofType:@"wav"];
    self.theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]
    autorelease];  //error: expected ';' before 'autorelease' and // error: expected statement before ']' token
    theAudio.delegate = self;
    [theAudio play];
    theAudio.numberOfLoops = -1;

   }

相关警告:

警告:属性theAudio"需要要定义的方法-theAudio" - 使用@synthesize、@dynamic 或提供一个方法实现

warning: property 'theAudio' requires method '-theAudio' to be defined - use @synthesize, @dynamic or provide a method implementation

警告:属性theAudio"需要方法 'setTheAudio:' 是定义 - 使用@synthesize、@dynamic 或提供方法实现

warning: property 'theAudio' requires the method 'setTheAudio:' to be defined - use @synthesize, @dynamic or provide a method implementation

告诉我您是否需要 .h 编码.但是那里没有错误.

tell me if you need .h coding. But there are no errors there.

推荐答案

这两个错误是因为您缺少上一行中的开头 [:

The two errors are because you are missing an opening [ in the previous line:

self.theAudio = [[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL] autorelease];

警告是因为您忘记了@implementation 中的@synthesize theAudio;(或忘记编写自定义的getter 和setter 方法).在运行时,如果你不修复它,你会得到一个未知的选择器异常.

The warnings are because you forgot @synthesize theAudio; in your @implementation (or forgot to write custom getter and setter methods). At runtime, you'll get an unknown selector exception if you don't fix that.

这篇关于XCode- 需要帮助解决错误(预期;和预期声明)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆