実行時にのみサイズがわかる構造体の配列を作成したい
NSMutableArray *styleSettingsArray = [NSMutableArray array];
NSString *fontAlignmentAttribute = [element attributeNamed:@"TextAlignment"];
if(fontAlignmentAttribute)
{
CTTextAlignment alignment = [self getTextAlignment:fontAlignmentAttribute];
CTParagraphStyleSetting styleSetting = {kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment};
[styleSettingsArray addObject:[NSValue valueWithBytes:&styleSettings objCType:@encode(CTParagraphStyleSetting)]];
}
// other posible attributes
CTParagraphStyleRef paragraphStyleRef = CTParagraphStyleCreate((__bridge const CTParagraphStyleSetting *)(styleSettingsArray), [styleSettingsArray count]);
[dictionary setObject:(__bridge id)(paragraphStyleRef) forKey:(NSString*)kCTParagraphStyleAttributeName];
CFRelease(paragraphStyleRef);
このコードは機能しません。
編集:
CTParagraphStyleCreate
の配列へのポインタを取りますCTParagraphStyleSetting
。
CTParagraphStyleSetting styleSettings[] = {
{ kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), alignment},
{...},
{...}
};
この配列を割り当てて、どのくらいの量が含まれるかを知らずに配列に追加するにはどうすればよいですか?(mallocはどのように使用しますか?)