0

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,

n00bProgrammer
  • 4,261
  • 3
  • 32
  • 60
Houssam
  • 125
  • 1
  • 12

1 Answers1

0

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

  • Please can you more explain ? – Houssam Nov 22 '14 at 08:01
  • yeah give me a few minutes I'll have to look up exactly how to do it. I don't usually mess with blocks much –  Nov 22 '14 at 08:03
  • something like that I'll have to look it up, but the underbar underbar block tell the compiler you'll want the value back after the block exits –  Nov 22 '14 at 08:07