 
 }
 
+/// The `NSKeyedArchiverDelegate` protocol defines the optional methods implemented
+/// by delegates of `NSKeyedArchiver` objects.
 public protocol NSKeyedArchiverDelegate : class {
     
-    // Informs the delegate that the object is about to be encoded.  The delegate
-    // either returns this object or can return a different object to be encoded
-    // instead.  The delegate can also fiddle with the coder state.  If the delegate
-    // returns nil, nil is encoded.  This method is called after the original object
-    // may have replaced itself with replacementObject(for:).
-    // This method is not called for an object once a replacement mapping has been
-    // setup for that object (either explicitly, or because the object has previously
-    // been encoded).  This is also not called when nil is about to be encoded.
-    // This method is called whether or not the object is being encoded conditionally.
+    /// Informs the delegate that `object` is about to be encoded.
+    ///
+    /// This method is called after the original object may have replaced itself
+    /// with `replacementObject(for:)`.
+    ///
+    /// This method is called whether or not the object is being encoded conditionally.
+    ///
+    /// This method is not called for an object once a replacement mapping has been set up
+    /// for that object (either explicitly, or because the object has previously been encoded).
+    /// This method is also not called when `nil` is about to be encoded.
+    ///
+    /// - Parameters:
+    ///   - archiver:   The archiver that invoked the method.
+    ///   - object:     The object that is about to be encoded.
+    /// - Returns:      Either object or a different object to be encoded in its stead.
+    ///                 The delegate can also modify the coder state. If the delegate
+    ///                 returns `nil`, `nil` is encoded.
     func archiver(_ archiver: NSKeyedArchiver, willEncode object: Any) -> Any?
     
-    // Informs the delegate that the given object has been encoded.  The delegate
-    // might restore some state it had fiddled previously, or use this to keep
-    // track of the objects which are encoded.  The object may be nil.  Not called
-    // for conditional objects until they are really encoded (if ever).
+    /// Informs the delegate that a given object has been encoded.
+    ///
+    /// The delegate might restore some state it had modified previously,
+    /// or use this opportunity to keep track of the objects that are encoded.
+    ///
+    /// This method is not called for conditional objects until they are actually encoded (if ever).
+    ///
+    /// - Parameters:
+    ///   - archiver:   The archiver that invoked the method.
+    ///   - object:     The object that has been encoded.
     func archiver(_ archiver: NSKeyedArchiver, didEncode object: Any?)
     
-    // Informs the delegate that the newObject is being substituted for the
-    // object. This is also called when the delegate itself is doing/has done
-    // the substitution. The delegate may use this method if it is keeping track
-    // of the encoded or decoded objects.
+    /// Informs the delegate that one given object is being substituted for another given object.
+    ///
+    /// This method is called even when the delegate itself is doing, or has done,
+    /// the substitution. The delegate may use this method if it is keeping track
+    /// of the encoded or decoded objects.
+    ///
+    /// - Parameters:
+    ///   - archiver:   The archiver that invoked the method.
+    ///   - object:     The object being replaced in the archive.
+    ///   - newObject:  The object replacing `object` in the archive.
     func archiver(_ archiver: NSKeyedArchiver, willReplace object: Any?, withObject newObject: Any?)
     
-    // Notifies the delegate that encoding is about to finish.
+
+    /// Notifies the delegate that encoding is about to finish.
+    ///
+    /// - Parameter archiver: The archiver that invoked the method.
     func archiverWillFinish(_ archiver: NSKeyedArchiver)
     
-    // Notifies the delegate that encoding has finished.
+
+    /// Notifies the delegate that encoding has finished.
+    ///
+    /// - Parameter archiver: The archiver that invoked the method.
     func archiverDidFinish(_ archiver: NSKeyedArchiver)
 }

        _encodeValue(objectRefs._bridgeToObjectiveC(), forKey: key)
    }
    
    /**
        Enables secure coding support on this keyed archiver. You do not need to enable
        secure coding on the archiver to enable secure coding on the unarchiver. Enabling
        secure coding on the archiver is a way for you to be sure that all classes that
        are encoded conform with NSSecureCoding (it will throw an exception if a class
        which does not NSSecureCoding is archived). Note that the getter is on the superclass,
        NSCoder. See NSCoder for more information about secure coding.
     */
    open override var requiresSecureCoding: Bool {
        get {
            return _flags.contains(ArchiverFlags.requiresSecureCoding)

        _encodeObject(object, forKey: nil, conditional: true)
    }

    /// Encodes a given object and associates it with a given key.
    ///
    /// - Parameters:
    ///   - objv:   The value to encode.
    ///   - key:    The key with which to associate `objv`.
    open override func encode(_ objv: Any?, forKey key: String) {
        _encodeObject(objv, forKey: key, conditional: false)
    }
    
    /// Encodes a reference to a given object and associates it with a given key
    /// only if it has been unconditionally encoded elsewhere in the archive with `encode(_:forKey:)`.
    ///
    /// - Parameters:
    ///   - objv:   The object to encode.
    ///   - key:    The key with which to associate the encoded value.
    open override func encodeConditionalObject(_ objv: Any?, forKey key: String) {
        _encodeObject(objv, forKey: key, conditional: true)
    }
