NSCoding

Example:

Swift 2.2
public class Stopwatch: NSCoding  {
...
@objc public required init?(coder decoder: NSCoder) {
    state = StateCode.from(int32: decoder.decodeIntForKey("state")) ?? .Zero
    timer = nil
    priorElapsed = NSTimeInterval(integerLiteral: decoder.decodeInt64ForKey("priorElapsed"))
    currentElapsed = 0
    let x = NSTimeInterval(integerLiteral: decoder.decodeInt64ForKey("originalStartTime"))
    originalStartTime = NSDate.init(timeIntervalSince1970: x)
    startTime = nil
}

@objc public func encodeWithCoder(coder: NSCoder) {
    coder.encodeInt(state.toInt32(), forKey: "state")
    if state != .Zero {
        coder.encodeInt64(Int64(priorElapsed + currentElapsed), forKey: "priorElapsed")
        if let orig = originalStartTime {
            coder.encodeInt64(Int64(orig.timeIntervalSince1970), forKey: "originalStartTime")
        }
    }
}