IOS NSMutableAttributedString crash EXC_BAD_ACCESS

661 views Asked by At

I have a problem that I hope that you can help me.

I use NSMutatableAttributedString to load html in UILabel but all time the application crash on

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

    self.attrStr = [[NSMutableAttributedString alloc] initWithData:[desc dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
});

I tried to add dispatch_async but nothing changed.

So Please help me,

1

There are 1 answers

3
AudioBubble On

You cannot assign a property in a block. It can be assigned in the block, but when the block leaves the heap or stack so does the pointer.

unless you do __block before the property goes into the block

I know like if I want to access a bool inside a block and keep the value when i exit I would do something like

__block BOOL myBool = NO;

then in my block I could set it ^{ myBool = YES; }

//myBool is YES now!

here give this a once over

[a link]https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Blocks/Articles/bxVariables.html