In iOS 12, the NSKeyedArchiver's initializer init(forWritingWith:) was deprecated. Xcode 10 recommends replacing it with the new initializer init(requiringSecureCoding:). The problem is that this initializer only sets the value of the requiresSecureCoding property of the NSCoder object, but it doesn't set the NSMutableData object that will contain the encoded data. The following is the original code propose by Apple to encode the metadata of a CKRecord (CloudKit record):
let data = NSMutableData()
let coder = NSKeyedArchiver.init(forWritingWith: data)
coder.requiresSecureCoding = true
record.encodeSystemFields(with: coder)
coder.finishEncoding()
The encodeSystemFields method of the CKRecord class requires an NSKeyedArchiver object (an NSCoder subclass) and the encoded data is stored in the NSMutableData object associated with this object. If I replace the init(forWritingWith:) initializer by the init(requiringSecureCoding:) initializer, I get an NSKeyedArchiver object, but this object is not associated with any NSMutableData object and therefore I don't get the record's metadata. I'm not sure how to complete the code to get the data produced by the NSKeyedArchiver object into an NSMutableData object.