There is no need creating a new typesetter, but we cannot use the old one.
Solution: use something else than a CTTypesetter, or split the attributed string into segments of hard line-breaks.
- (void)wordWrapLineWithIndex:(int)index
{
NSRange lineRange = [self rangeOfLineWithIndex:index];
NSLog(@"Word wrapping on line:\"%@\"",[self.attributedString.string substringWithRange:lineRange]);
CGRect insetBounds = CGRectInset([self bounds], MARGIN, MARGIN);
CGFloat boundsWidth = CGRectGetWidth(insetBounds);
// Calculate the lines
CFIndex start = lineRange.location;
CFIndex currentIndex = index;
NSUInteger length = CFAttributedStringGetLength((__bridge CFAttributedStringRef)(self.attributedString));
NSLog(@"Deleting the first line with an index of %li", currentIndex);
[self deleteLineWithNumber:index];
// This is very time-consuming, but reusing the old framesetter seem to cause trouble.
CTTypesetterRef typesetter = CTTypesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(self.attributedString));
There is no need creating a new typesetter, but we cannot use the old one.
Solution: use something else than a CTTypesetter, or split the attributed string into segments of hard line-breaks.