繁体   English   中英

使用未声明的标识符

[英]Use of undeclared identifier

我正在尝试使用这个项目 ,它是Objective-C的合成器,用于我正在构建的iPhone应用程序。 但是,我遇到了MHAudioBufferPlayer类的问题。

MHAudioBufferPlayer.m类中 ,我收到了一堆Use of undeclared identifier _gain_playing_audioFormat Use of undeclared identifier错误。 这是有道理的,因为这些标识符永远不会在它们前面用下划线声明。 但是,它们在没有下划线的MHAudioBufferPlayer.h类中声明。

因为我是Objective-C的新手,所以我对此感到困惑。 下划线表示要采取特殊措施吗? 它应该被翻译成self.gainself.playing等吗? 我怎样才能解决这个问题? 或者这个代码只是错误吗?

- (id)initWithSampleRate:(Float64)sampleRate channels:(UInt32)channels bitsPerChannel:(UInt32)bitsPerChannel packetsPerBuffer:(UInt32)packetsPerBuffer
{
    if ((self = [super init]))
    {
        _playing = NO;
        _playQueue = NULL;
        _gain = 1.0;

        _audioFormat.mFormatID         = kAudioFormatLinearPCM;
        _audioFormat.mSampleRate       = sampleRate;
        _audioFormat.mChannelsPerFrame = channels;
        _audioFormat.mBitsPerChannel   = bitsPerChannel;
        _audioFormat.mFramesPerPacket  = 1;  // uncompressed audio
        _audioFormat.mBytesPerFrame    = _audioFormat.mChannelsPerFrame * _audioFormat.mBitsPerChannel/8;
        _audioFormat.mBytesPerPacket   = _audioFormat.mBytesPerFrame * _audioFormat.mFramesPerPacket;
        _audioFormat.mFormatFlags      = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;

        _packetsPerBuffer = packetsPerBuffer;
        _bytesPerBuffer = _packetsPerBuffer * _audioFormat.mBytesPerPacket;

        [self setUpAudio];
    }
    return self;
}

如果您使用的是Xcode4.4以后的新编译器,那么对于您的每个属性,它会创建一个自动合成,并使用_(下划线)作为前缀。

就像,如果你创建了@property.... playing;

然后编译器创建@synthesize playing=_playing;

如果您使用的是旧版Xcode,则需要手动完成。

根据您使用的XCode版本和编译器,有不同的方法。 我不知道你对OOP有多熟悉,如果你不是我建议你读一下定制者和吸气剂和物品,因为它是你从现在开始做的几乎所有事情的基础。

一些例子,老派风格,将创造一个伊娃。 在你的.h:

@interface TheViewController : UIViewController{
    NSString *theString;
}

一点点新风格,将在你的.h中创建setter和getter。

@interface TheViewController : UIViewController

@property (nonatomic, weak) NSString *theString;

在.m文件中:

@implementation TheViewController

@synthesize theString = _theString;

可以通过_theString或self.theString访问

这样做的新方式。 在你的.h文件中:

@property (nonatomic, weak) NSString *theString;

编译器将以上述方式创建所有内容。

希望对你有所帮助。

由Xcode => 4.4生成的@synthesize作为默认值。 如果您没有显式创建自己的@synthesize语句 ,则由Xcode为您创建的生成的私有实例变量ivar具有前导下划线' '。 在向此属性发送消息时, 您必须包含前导' '(通常是UI元素作为来自controller.m文件的插座)。

那是

@property textField;

[_textField setStringValue:@“foo”]; 如果你不写'@synthesize'。

编译器为您完成了这项工作,并通过合成getter / setter创建了一个私有实例变量。 惯例是使私有ivar成为前导下划线前面的属性名称。

要么

@synthesize textField; @property textField; [textField setStringValue:@“foo”]; 如果你自己编写'@synthesize'或者是<Xcode 4.4。

在这里,编译器没有为你完成,你的ivar名称/属性名称是相同的,可以使用没有前导'_'。

祝好运。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM