Skip to content

Instantly share code, notes, and snippets.

@ignazioc
Last active June 14, 2018 23:00

Revisions

  1. ignazioc revised this gist Jun 14, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions attribute.swift
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ import UIKit
    import XCTest

    class UserManagerTests: XCTestCase {
    func testLoggingIn() {
    func testConvertToHtml() {
    self.measure {
    let htmlString = String.init(repeating: "<p>I am normal</p><b>asdfasd</b><i>asdfasdfa</i>", count: 1000)
    _ = htmlString.convertHtml()
    @@ -21,4 +21,4 @@ extension String {
    }
    }

    UserManagerTests.defaultTestSuite.run()
    UserManagerTests.defaultTestSuite.run()
  2. ignazioc created this gist Jun 14, 2018.
    24 changes: 24 additions & 0 deletions attribute.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    //: Playground - noun: a place where people can play

    import UIKit
    import XCTest

    class UserManagerTests: XCTestCase {
    func testLoggingIn() {
    self.measure {
    let htmlString = String.init(repeating: "<p>I am normal</p><b>asdfasd</b><i>asdfasdfa</i>", count: 1000)
    _ = htmlString.convertHtml()
    }
    }
    }

    extension String {
    func convertHtml() -> NSAttributedString {

    let modifiedFont = String(format:"<span style=\"font-family: '-apple-system', 'HelveticaNeue'; font-size: 17\">%@</span>", self)
    let data = modifiedFont.data(using: .utf8)!
    return try! NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
    }
    }

    UserManagerTests.defaultTestSuite.run()