从苹果那里得到这个奇怪的错误。昨天一切都很好

时间:2014-03-31 15:02:02

标签: ios iphone

2周前我开始尝试修复我的应用程序,以便它们可以与Apple一起发布。当应用程序完美运行时。在今天早上开始使用XCode之前,我启动了模拟器并注意到我的应用程序运行良好。然后我继续打开Xcode,我所做的就是改变!事情,现在没有任何作用。

我是一个业余爱好者,所以很多自然而然的事情看起来像是我的愚蠢问题。

我不确定如何解码汇编语言。有人可以帮我弄清楚发生了什么。这个功能在这里显示问题所在。它说“本地声明'soundfilePath'隐藏实例变量”& “本地声明'soundfileURL'隐藏实例变量”

- (void)viewDidLoad
{
    [super viewDidLoad];

    playButton.enabled = NO;
    stopButton.enabled = NO;

    NSArray *dirPaths;
    NSString *docsDir;

    dirPaths = NSSearchPathForDirectoriesInDomains(
                                                   NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = [dirPaths objectAtIndex:0];
    NSString *soundFilePath = [docsDir
                               stringByAppendingPathComponent:@"sound.caf"];

    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

    NSDictionary *recordSettings = [NSDictionary 
                                    dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt:AVAudioQualityMin],
                                    AVEncoderAudioQualityKey,
                                    [NSNumber numberWithInt:16], 
                                    AVEncoderBitRateKey,
                                    [NSNumber numberWithInt: 2], 
                                    AVNumberOfChannelsKey,
                                    [NSNumber numberWithFloat:44100.0], 
                                    AVSampleRateKey,
                                    nil];

    NSError *error = nil;

    audioRecorder = [[AVAudioRecorder alloc]
                     initWithURL:soundFileURL
                     settings:recordSettings
                     error:&error];

    if (error)
    {
        NSLog(@"error: %@", [error localizedDescription]);
    } else {
        [audioRecorder prepareToRecord];
    }




    // Do any additional setup after loading the view, typically from a nib.
}

这是我得到的一些程序集错误消息。

0x02622a4f< + 0011> mov 0x8(%ebp),%esi

2 个答案:

答案 0 :(得分:2)

  

“本地声明'soundfilePath'隐藏实例变量”& “本地声明'soundfileURL'隐藏实例变量”

这意味着您已声明了一个实例变量(在.m文件顶部的大括号内或在头文件中),其名称与本地变量相同。你有以下几行:

NSString *soundFilePath = [docsDir
                           stringByAppendingPathComponent:@"sound.caf"];

NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

在文件的其他位置,您还将拥有以下这些行:

NSString *soundFilePath;
NSURL *soundFileURL;

使用它们都不是一个好主意。

重命名局部变量,或使用实例变量。如果在类的其他位置使用这些变量,请使用实例变量:

soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"];

soundFileURL = [NSURL fileURLWithPath:soundFilePath];

答案 1 :(得分:1)

您已经拥有名为soundFilePathsoundFileURL的属性,当您在上面显示的方法中声明这些局部变量时,您正在“遮蔽”它们。也就是说,您的局部变量优先于属性使用,这会弄乱您的代码。

修复是以下两件事之一:

更改局部变量的名称

如果您的代码中有@synthesise个属性的行,请将其删除。现代Xcode自动合成属性存储,并且在它们前面添加_,因此您的属性变量将为_soundFilePath_soundFileURL,并且您不会将它们视为阴影了。

相关问题