Iphone 未声明标识符的使用
我正在尝试为我正在构建的iPhone应用程序使用Objective-C合成器。但是,我在Iphone 未声明标识符的使用,iphone,ios,objective-c,audiotoolbox,Iphone,Ios,Objective C,Audiotoolbox,我正在尝试为我正在构建的iPhone应用程序使用Objective-C合成器。但是,我在mhadiobufferplayer类中遇到了问题 在中,我得到了一堆使用未声明标识符的错误,用于\u增益,\u播放,以及\u音频格式。这是有意义的,因为这些标识符前面从来没有下划线。但是,它们在mhadiobufferplayer.h类中声明,不带下划线 我对Objective-C有点困惑,因为我是新手。下划线是否表示要采取的特殊行动?它应该被翻译成self.gain,self.playing等吗。?我怎样
mhadiobufferplayer
类中遇到了问题
在中,我得到了一堆使用未声明标识符的错误,用于\u增益
,\u播放
,以及\u音频格式
。这是有意义的,因为这些标识符前面从来没有下划线。但是,它们在mhadiobufferplayer.h
类中声明,不带下划线
我对Objective-C有点困惑,因为我是新手。下划线是否表示要采取的特殊行动?它应该被翻译成self.gain
,self.playing
等吗。?我怎样才能解决这个问题?或者这段代码只是个bug
- (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以后版本附带的新编译器,那么它会为您的每个属性创建一个自动合成,前缀为(下划线)
例如,如果您创建了@属性。。。。玩代码>
然后编译器创建@syntheticplaying=\u playing代码>
如果您使用的是旧版本的Xcode,则需要手动执行此操作。根据您使用的Xcode版本和编译器,有不同的执行方法。我不知道你对OOP有多熟悉,如果你不熟悉,我建议你读一读关于setter、getter和objects的知识,因为它是你从现在开始将要做的几乎所有事情的基础
一些老派风格的例子将创建ivar。在您的.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;
编译器将以上述方式创建所有内容
希望这对您有所帮助。@synthesis由Xcode=>4.4作为默认值生成。如果您没有显式创建自己的@synthesis语句,那么Xcode为您创建的生成的私有实例变量ivar将有一个前导下划线“”。向此服务器发送邮件时必须包含前导“”
属性(通常将UI元素作为controller.m文件的出口)
就是
@属性文本字段
[_textfieldsetstringvalue:@“foo”];如果你不写“@synthetic”
编译器已经为您完成了这项工作,并通过合成getter/setter生成了一个私有实例变量。约定是将私有ivar设置为以下划线开头的属性名称
或
@合成文本场;
@属性文本字段;
[textField setStringValue:@“foo”];如果你写了自己的“@synthetic”或
在这里,编译器没有为您这样做,您的ivar名称/属性名称是相同的,并且可以在不带前导“\”的情况下使用
祝你好运。你试过在实现文件中合成属性吗?@0x7fffffff你能给出具体的语法吗?例如,对于\u gain
?另外,如果有人可以建议使用不同的合成音合成器(可以同时播放多个音调的合成器)对于Objective-c&iOS,这也会很有帮助。您将@synthesis表达式放在哪里?@varatis就在@implementation
行之后。在@implementation之后的nxt行中,您的类{