我收到“程序收到信号: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 框架
最佳答案
在更改 iVar 的值之前,您应该始终检查 init
方法中的 self
是否不为 nil:
- (id)init
{
self = [super init];
if (self)
{
speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
}
return self;
}
关于objective-c - 当我尝试创建 NSSpeechSynthesizer 实例时获取 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7791683/