Ending TextList Madness

I am just playing with NSTextList by creating a sample iOS app. The following is my code.

import UIKit

class ViewController: UIViewController {
	lazy var textView: UITextView = {
		let textView = UITextView()
		textView.text = ""
		textView.contentInsetAdjustmentBehavior = .automatic
		textView.backgroundColor = .white
		textView.font = UIFont.systemFont(ofSize: 20.0)
		textView.textColor = .black
		textView.translatesAutoresizingMaskIntoConstraints = false
		NSLayoutConstraint.activate([
			textView.widthAnchor.constraint(equalToConstant: 600.0),
			textView.heightAnchor.constraint(equalToConstant: 600.0)
		])
		return textView
	}()
	
	lazy var button: UIButton = {
		let button = UIButton()
		button.setTitle("End list", for: .normal)
		button.setTitleColor(.white, for: .normal)
		button.setTitleColor(.lightGray, for: .highlighted)
		button.backgroundColor = .black
		button.layer.cornerRadius = 8.0
		button.addTarget(self, action: #selector(fixTapped), for: .touchUpInside)
		button.translatesAutoresizingMaskIntoConstraints = false
		NSLayoutConstraint.activate([
			button.widthAnchor.constraint(equalToConstant: 100.0),
			button.heightAnchor.constraint(equalToConstant: 42.0)
		])
		return button
	}()
	
	override func viewDidLoad() {
		super.viewDidLoad()
		
		view.backgroundColor = .systemBlue
		view.addSubview(textView)
		view.addSubview(button)
		
		let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
		view.addGestureRecognizer(tapGesture)
		
		NSLayoutConstraint.activate([
			textView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
			textView.centerYAnchor.constraint(equalTo: view.centerYAnchor)
		])
		NSLayoutConstraint.activate([
			button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
			button.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -20.0)
		])
		
		let list = NSTextList(markerFormat: .diamond, options: 0)
		list.startingItemNumber = 1
		let paragraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
		paragraphStyle.textLists = [list]
		let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 24.0)]
		let attributedStr = NSMutableAttributedString(string: "\n\n\n\n\n", attributes: attributes)
		textView.textStorage.setAttributedString(attributedStr)
	}
	
	@objc func fixTapped() {

	}
	
	@objc func dismissKeyboard() {
		view.endEditing(true)
	}
}

When the app launches itself, I get 5 lines of diamond guys as shown in the following screenshot.

If I keep pressing the delete key with a connected keyboard, the list will be gone as shown below.

But if I press the RETURN key several times, the diamond list will come back as shown below.

So how can I end this June TextList madness? In code, I have the dismissKeyboard function if I can end this madness programmatically.

Thanks,

Señor Tomato Spaghetti

Chief Janitor at

Southeastern Tomato Spaghetti Trade Association

Ending TextList Madness
 
 
Q