NSAttributedString not rendering on time - Swift
<p>So, I'm having issues in a project where certain strings are not being rendered properly in some old iPhones with certain iOS versions (specifically it does  not work for iPhone 5 with iOS10, while it does for iOS9.3, oddly enough). To reduce the issue, I wrote this code:</p>

<pre><code>import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var label: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Long HTML, although we'll make it even larger to prove a point
        let string = "&lt;h1&gt;Thing 1&lt;/h1&gt;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. &lt;/p&gt;&lt;h1&gt;Thing 2&lt;/h1&gt;&lt;p&gt;Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. &lt;/p&gt;&lt;h1&gt;Thing 3&lt;/h1&gt;&lt;p&gt;Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. &lt;/p&gt;&lt;h1&gt;Thing 4&lt;/h1&gt;&lt;p&gt;Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. &lt;/p&gt;&lt;h1&gt;Thing 5&lt;/h1&gt;&lt;p&gt;Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. &lt;/p&gt;&lt;h1&gt;Thing 6&lt;/h1&gt;&lt;p&gt;Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. &lt;/p&gt;"

        let attrStr = try! NSAttributedString(
            data: (string + string + string + string + string + string + string + string).data(using: String.Encoding.unicode,allowLossyConversion: true)!,
            options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
            documentAttributes: nil)

        label.attributedText = attrStr
        label.backgroundColor = UIColor(red:0.00, green:1.00, blue:0.00, alpha:1.0)
    }
}
</code></pre>

<p>Simple enough. Of course the real issue is more complicated than this, but the idea is the same.</p>

<p>So, in an iPhone 7, all works fine:</p>

<p><a href="https://i.stack.imgur.com/9zQdJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9zQdJ.png" alt="enter image description here"></a></p>

<p>However, when loading it on an iPhone 4s:</p>

<p><a href="https://i.stack.imgur.com/pso7A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pso7A.png" alt="enter image description here"></a></p>

<p>When debugging, <code>attrStr</code> seems to be properly set in both cases.</p>

<p>Any ideas? My theory is that older phones are too slow to render this on time, but I'm not quite sure how to workaround this. </p>

<p>Thanks!</p>

<p>EDIT: For those that asked, this is the Storyboard:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="JzW-qG-LFG"&gt;
    &lt;dependencies&gt;
        &lt;deployment identifier="iOS"/&gt;
        &lt;plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/&gt;
        &lt;capability name="Constraints to layout margins" minToolsVersion="6.0"/&gt;
        &lt;capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/&gt;
    &lt;/dependencies&gt;
    &lt;scenes&gt;
        &lt;!--View Controller--&gt;
        &lt;scene sceneID="9PR-d2-hNU"&gt;
            &lt;objects&gt;
                &lt;viewController id="JzW-qG-LFG" customClass="ViewController" customModule="things" customModuleProvider="target" sceneMemberID="viewController"&gt;
                    &lt;layoutGuides&gt;
                        &lt;viewControllerLayoutGuide type="top" id="VGp-YT-QQN"/&gt;
                        &lt;viewControllerLayoutGuide type="bottom" id="SeT-t7-CD0"/&gt;
                    &lt;/layoutGuides&gt;
                    &lt;view key="view" contentMode="scaleToFill" id="gtg-CO-E9d"&gt;
                        &lt;rect key="frame" x="0.0" y="0.0" width="375" height="667"/&gt;
                        &lt;autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/&gt;
                        &lt;subviews&gt;
                            &lt;label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Id1-A1-RaT"&gt;
                                &lt;fontDescription key="fontDescription" type="system" pointSize="17"/&gt;
                                &lt;nil key="textColor"/&gt;
                                &lt;nil key="highlightedColor"/&gt;
                            &lt;/label&gt;
                        &lt;/subviews&gt;
                        &lt;color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/&gt;
                        &lt;constraints&gt;
                            &lt;constraint firstAttribute="trailingMargin" secondItem="Id1-A1-RaT" secondAttribute="trailing" id="0qp-Rk-PC2"/&gt;
                            &lt;constraint firstItem="Id1-A1-RaT" firstAttribute="leading" secondItem="gtg-CO-E9d" secondAttribute="leadingMargin" id="3Vc-he-HqH"/&gt;
                            &lt;constraint firstItem="Id1-A1-RaT" firstAttribute="top" secondItem="VGp-YT-QQN" secondAttribute="bottom" id="7IE-fY-4H0"/&gt;
                        &lt;/constraints&gt;
                    &lt;/view&gt;
                    &lt;navigationItem key="navigationItem" id="Opz-px-hsl"/&gt;
                    &lt;connections&gt;
                        &lt;outlet property="label" destination="Id1-A1-RaT" id="TNv-G9-ASE"/&gt;
                    &lt;/connections&gt;
                &lt;/viewController&gt;
                &lt;placeholder placeholderIdentifier="IBFirstResponder" id="qlV-6d-ISJ" userLabel="First Responder" sceneMemberID="firstResponder"/&gt;
            &lt;/objects&gt;
            &lt;point key="canvasLocation" x="2848.8000000000002" y="-280.20989505247377"/&gt;
        &lt;/scene&gt;
    &lt;/scenes&gt;
&lt;/document&gt;
</code></pre>