尝试创建NSSpeechSynthesizer实例时获取EXC_BAD_ACCESS

时间:2011-10-17 09:19:45

标签: objective-c xcode macos cocoa

我得到"节目收到信号:EXC_BAD_ACCESS"我无法弄清楚原因

这是我的界面

#import <Cocoa/Cocoa.h>


@interface AppController : NSObject {
    NSSpeechSynthesizer *speechSynth;
}

和实施

#import "AppController.h"


    @implementation AppController

    - (id)init
    {
        self = [super init];

         // HERE I GET Program received signal: EXC_BAD_ACCESS
         speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
        return self;
    }
    @end

我已经包含了Cocoa和AppKit框架

1 个答案:

答案 0 :(得分:0)

在更改iVars的值之前,您应该始终检查self方法中的init是否为零:

- (id)init
{
    self = [super init];
    if (self)
    {
        speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
    }
    return self;
}