how to create and allocate a C buffer as part of an objective C class

ぃ、小莉子 提交于 2019-11-27 15:57:51

it fails because data is a null pointer when you set its content.

the easy way to do this is:

enum { ITEM_CAPACITY = 100 };

typedef struct DataStruct {
    char content[ITEM_CAPACITY];
    UInt32 size;
} DataStruct;

@interface AudioItem : NSObject
{        
@private
    DataStruct data;
}

@implementation AudioItem
- (id)initWithID:(NSString *)itemID
{
    self = [super init];
    if (0 == self) return;
    data.size = ITEM_CAPACITY;
    return self;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!