Our DNA is written in Swift
Jump

Enhancement: Make NSTextList Public

Whenever I am tasked with adding a rich text editor to an app, I check if Apple has since done something in UIKit to support lists. Since they revamped the text system in iOS 7, unifying large portions with how they are dealing with text on macOS, I am getting my hopes up for every new release of iOS.

macOS is using the NSTextList class to represent lists and the code below is provides proof that this class also exists on iOS. So this Radar requests – probably not for for the first time – for NSTextList to be made public. It is filed as rdar://28254852 and on Open Radar.

Ad

Summary

When parsing HTML into an NSAttributedString, your parser adds an NSTextList object when it encounters

<OL><LI>Item</LI></OL>.

and sets it on the (private) textLists property on NSParagraphStyle.

This request is to promote both the NSTextList class as well as the textLists property to public API.

Without this access we are not able to use UITextView for modern rich text editing. Every modern rich text editor allows inserting and updating of ordered/unordered lists.

Since NSTextList seems to have been available since iOS 7 we believe you could make it public retroactively in a minor update to iOS 10.

Steps to Reproduce

Paste the following into a Playground:

import UIKit

let body = "<ol><li>one</li></ol>"

let data = body.dataUsingEncoding(NSUTF8StringEncoding)
let options : [String: AnyObject] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding
]

let attribStr = try! NSAttributedString(data: data!, options: options, 
                                        documentAttributes: nil)
print(attribStr)

Expected Results

The print shows that there is an NSTextList object present. But there is no public API to work with it.

Actual Results

I would expect to be able to access the textLists property of the paragraph style.

Proof for NSTextList on iOS


Also published on Medium.


Categories: Bug Reports

1 Comment »

Trackbacks

  1. DTCoreText 1.6.21 | Cocoanetics – Techvibesnow

Leave a Comment

%d bloggers like this: