Sub-Classing NSTextStorage Causes Significant Memory Issues

后端 未结 1 377
一整个雨季
一整个雨季 2021-01-01 03:42

I have a custom UITextView that takes advantage of Apple\'s TextKit by defining a custom NSTextStorage class, however, when I use my subclass for t

相关标签:
1条回答
  • 2021-01-01 04:21

    Wow.... weird, it got fixed when I changed the type of storage to NSTextStorage....

    typealias PropertyList = [String : AnyObject]
    
    class BMTextStorage : NSTextStorage {
    
        overrride var string: String {
            return storage.string
        }
    
        private var storage = NSTextStorage()
    
        override func attributesAtIndex(location: Int, effectiveRange range: NSRangePointer) -> PropertyList {
            return storage.attributesAtIndex(location, effectiveRange: range)
        }
    
        override func replaceCharactersInRange(range: NSRange, withString str: String) {
            storage.replaceCharactersInRange(range, withString: str)
            edited([.EditedAttributes, .EditedCharacters], range: range, changeInLength: str.length - range.length)
        }
    
        override func setAttributes(attrs: PropertyList?, range: NSRange) {
            storage.setAttributes(attrs, range: range)
            edited([.EditedAttributes], range: range, changeInLength: 0)
        }
    
        override func processEditing() {
            super.processEditing()
        }
    
     }
    
    0 讨论(0)
提交回复
热议问题