Foundation encodes `encode(_:forKey: "UID")` as a `$top` dictionary whose single key is `UID`. The keyed archive projection treated every one-key `UID`/`CF$UID` dictionary as a reference marker, so that root became a malformed reference and the real link to its object was lost. Treat a one-key dictionary as a UID only when its value is a number, matching the binary decoder's UID shape and Foundation's XML `CF$UID` rule; otherwise descend into it as an ordinary dictionary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 lines
312 B
Swift
8 lines
312 B
Swift
import Foundation
|
|
|
|
// Encode the root under a key that matches the UID marker spelling.
|
|
let archiver = NSKeyedArchiver(requiringSecureCoding: false)
|
|
archiver.encode("payload" as NSString, forKey: "UID")
|
|
archiver.finishEncoding()
|
|
try archiver.encodedData.write(to: URL(fileURLWithPath: CommandLine.arguments[1]))
|