NSCoding is a protocol from Apple Foundation framework. The NSCoding protocol declares the two methods that a class must implement so that instances of that class can be encoded and decoded.
The NSCoding
protocol declares the two methods that a class must implement so that instances of that class can be encoded and decoded. This capability provides the basis for archiving (where objects and other structures are stored on disk) and distribution (where objects are copied to different address spaces).
These two methods in the NSCoding
protocol are:
encodeWithCoder:
Encodes the receiver using a given archiver. (required)
-(void)encodeWithCoder:(NSCoder *)encoder
initWithCoder:
Returns an object initialized from data in a given unarchiver. (required)
- (id)initWithCoder:(NSCoder *)decoder
And in Swift swift:
init(coder decoder: NSCoder!)
func encodeWithCoder(_ encoder: NSCoder!)