我正在尝试在Mac OS X API(音频队列服务)中遵循C++接口的教程,但是在Cocoa(实际上只是基础)应用程序(实际上只是一个'工具').它有一个如下所示的结构:
static const int kNumberBuffers = 3; // 1 struct AQPlayerState { AudioStreamBasicDescription mDataFormat; // 2 AudioQueueRef mQueue; // 3 AudioQueueBufferRef mBuffers[kNumberBuffers]; // 4 AudioFileID mAudioFile; // 5 UInt32 bufferByteSize; // 6 SInt64 mCurrentPacket; // 7 UInt32 mNumPacketsToRead; // 8 AudioStreamPacketDescription *mPacketDescs; // 9 bool mIsRunning; // 10 };
我将第4项转换为Objective-C时遇到了很多麻烦,因为我无法弄清楚如何@synthesize
使用C数组.具体来说,这是我到目前为止:
#import#import @interface PlayerState : NSObject { AudioStreamBasicDescription dataFormat; AudioQueueRef queue; AudioQueueBufferRef _buffers[3]; int audioFile; // make this an actual type? UInt32 bufferByteSize; SInt64 currentPacket; UInt32 numPacketsToRead; AudioStreamPacketDescription* packetDescs; bool isRunning; } @property(assign) AudioStreamBasicDescription dataFormat; @property(assign) AudioQueueRef queue; @property(assign) AudioQueueBufferRef buffers; @property(assign) int audioFile; @property(assign) UInt32 bufferByteSize; @property(assign) SInt64 currentPacket; @property(assign) UInt32 numPacketsToRead; @property(assign) AudioStreamPacketDescription* packetDescs; @property(assign) bool isRunning; @end
#import "PlayerState.h" @implementation PlayerState @synthesize dataFormat; @synthesize queue; @synthesize buffers; @synthesize audioFile; @synthesize bufferByteSize; @synthesize currentPacket; @synthesize numPacketsToRead; @synthesize packetDescs; @synthesize isRunning; @end
@synthesize buffers
无法编译如下:"错误:合成属性'缓冲区'必须与兼容的ivar命名相同或必须明确命名为ivar"
这显然是因为相应的ivar被命名_buffers
而不是buffers
- 但这是必要的,因为我不能将属性定义为数组(我可以吗?@property(assign) *AudioQueueBufferRef buffers
是语法错误)
我可以做什么来将ivar定义为AudioQueueBufferRef
结构数组,或者合成属性以使其引用_buffers
数组?