Problem using CTFontRef in a loop to create an NSMutableAttributedString

I need to create an NSMutableAttributedString with different CTFontRef and CTParagraphStyleRef for different ranges on this line.

I am trying to create it by putting the following code in a loop and changing the range as I need,

CTFontRef normalFontRef = CTFontCreateWithName((CFStringRef)@"CourierNewPSMT", fontsize, NULL);
NSDictionary* normalFontAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:(id)normalFontRef,(NSString*)kCTFontAttributeName, nil];
[attributedString addAttributes:normalFontAttribute range:range];

CFRelease(normalFontRef);
[normalFontAttribute release];
normalFontAttribute = nil;

CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, theNumberOfSettings);
NSDictionary* paragraphAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:(id)paragraphStyle,(NSString*)kCTParagraphStyleAttributeName, nil];
[attributedString addAttributes:paragraphAttribute range:range];

CFRelease(paragraphStyle);
paragraphAttribute release];
paragraphAttribute = nil;

My problem:

The application crashes out of the device after some iteration of the loop without any details. Just close the no crash report application, there is no message in the console, there is no gdb breakpoint.

: NSMutableAttributedString . - , NSMutableAttributedString. NSMutableAttributedString, , .

//works fine
attributtedString = [[NSMutableAttributedString alloc] initWithString:stringContent];

//not working 
attributtedString   = [self createattributtedString:stringContent];
//this createattributtedString: method contain the first listed code 

,

+1
1

.

-1

All Articles