Skip to content

Instantly share code, notes, and snippets.

@mjarvis
Last active October 16, 2017 22:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjarvis/8345661 to your computer and use it in GitHub Desktop.
Save mjarvis/8345661 to your computer and use it in GitHub Desktop.
This GIST is to help explain the behaviour of NSAttributedString's "initWithData:options:documentAttributes:error:" when used with NSHTMLDocumentType.At first glance, one would expect the output here to be "1, 2, 3", But after some careful reading of the documentation, and if you run the code here, we find that not to be true.
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"3");
});
NSLog(@"1");
[[NSAttributedString alloc] initWithData:[@"<span>html!</span>" dataUsingEncoding:NSUTF8StringEncoding]
options:@{
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
}
documentAttributes:nil
error:nil];
NSLog(@"2");
/*
Expected output: 1 2 3
Actual Output: 1 3 2
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment