I want to make an array of structs of which the size is known only at runtime
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);
This code does not work.
EDIT:
CTParagraphStyleCreate takes a pointer to an array of CTParagraphStyleSetting, such as
CTParagraphStyleSetting styleSettings[] = {
{ kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), alignment},
{...},
{...}
};
How can I allocate this array, and add stuff to it without knowing how much stuff will be in it ? (how do I use malloc ?)
CTParagraphStyleCreatedocumentation, there's a reference toCTParagraphStyleSettingtypedef, you can't just castNSArraytoCTParagraphStyleSetting.CTParagraphStyleCreategave me an example in seconds :)