@在Objective-C 2.0中合成一个C数组结构

@在Objective-C 2.0中合成一个C数组结构,第1张

概述我正在尝试在Mac OS X API(音频队列服务)中使用C接口的教程,但是在 Cocoa(实际上只是基础)应用程序(嗯,实际上只是一个’工具’).它有一个如下所示的结构: static const int kNumberBuffers = 3; // 1struct AQPlayerState { AudioStreamBasi 我正在尝试在Mac OS X API(音频队列服务)中使用C接口的教程,但是在 Cocoa(实际上只是基础)应用程序(嗯,实际上只是一个’工具’).它有一个如下所示的结构:

static const int kNumberBuffers = 3;                              // 1struct 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数组.具体来说,这是我到目前为止:

PlayerState.h

#import <Foundation/Foundation.h>#import <AudioToolBox/AudioQueue.h>@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

PlayerState.m

#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缓冲区无法编译如下:“错误:合成属性’缓冲区’必须与兼容的ivar命名相同或必须明确命名为ivar”

这显然是因为相应的ivar被命名为_buffers而不是缓冲区 – 但这是必要的,因为我无法将属性定义为数组(可以吗?@property(assign)* AudioQueueBufferRef buffers是语法错误)

我该怎么做才能将ivar定义为AudioQueueBufferRef结构数组,或者合成属性使其引用_buffers数组?

解决方法

@synthesize buffers fails to compile as follows: “error: synthesized property ‘buffers’ must either be named the same as a compatible ivar or must explicitly name an ivar”

尝试:

@synthesize buffers = _buffers;
总结

以上是内存溢出为你收集整理的@在Objective-C 2.0中合成一个C数组结构全部内容,希望文章能够帮你解决@在Objective-C 2.0中合成一个C数组结构所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1017362.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存