How to Initialize NSTextStorage with a String in Swift

余生颓废 提交于 2019-11-29 11:04:06

It seems the way to do things, is to add the NSLayoutManager to the NSTextStorage object, (using addLayoutManager:) rather than setting the textStorage property on the layout manager.

From Apple's documents:

This method is invoked automatically when you add an NSLayoutManager to an NSTextStorage object; you should never need to invoke it directly, but you might want to override it. If you want to replace the NSTextStorage object for an established group of text-system objects containing the receiver, use replaceTextStorage:.

Link to setTextStorage: for NSLayoutManager

Presumably something gets done in 'addLayoutManager:' which doesn't get done in setTextStorage, causing the crash.

You might also want to increase the scope of the textStorage variable, if it appears that it's getting cleared up once viewDidLoad finish.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!