I'm really new using the NSCoding functionality, I'm trying to create persistence of data of an attributedString, particularly a UIColor that is passed through a delegate. I haven't found a tutorial that encodes values that are not declared and initialized in the same class in which the NSCoding protocol is conformed.
I have the following code, which is the method that conforms to the protocol I created, and assigns the passed color value as an attribute to the attributedString.
func didSelectColorCell(color: UIColor) {
let coder = NSCoder.init()
color.encode(with: coder)
noteTextView.setAttributedValueAtSelectedTextRange(NSForegroundColorAttributeName, value: color)
}
The app crashes, and sends me a warning "cannot be sent to an abstract object of class NSCoder: Create a concrete instance!" I'm really lost on how to procede. I don't know how to adapt this tutorial http://nshipster.com/nscoding/ to my scenario.
Can someone please provide me guidance on how to order my ideas or how does NSCoding work with delegates? Any help would be appreciated :)
Define a class to implement the NSCoding protocol (Playground sample):
In your code:
To read the saved data: