// A record's card (`CottonValues/DeckCard.swift`) read off the record the// core resolved it on (`@card`), and the card a record stands on when its// table names none. Saying a card the deck cannot read is the app's: the// value module logs nothing.importCottonValuesimport osimportSwiftUIextensionDeckCard {/// The record's card; nil when it carries none, and nil with a logged/// `DeckCardFailure` when it carries one the deck cannot read — never a/// silent nil, because the deck holds only rows with a card and an/// unreadable one empties it while the strip still counts the rows.publicinit?(_ record: TableRecord) {switchSelf.read(record[Self.key]) {casenil: returnnilcase .success(let card): self = cardcase .failure(let failure):DeckCardLog.unreadable(record.id, failure)returnnil } }/// The card a record stands on when its table names no card at all (a/// table the owner made): the plain face, headed by what the record is/// called — never no card, which would leave it off its own deck. Nil/// for a table with a card, whose record carries the core's.staticfunc plain(_ record: TableRecord, in definition: TableDefinition) -> DeckCard? { definition.card == nil ? named(record, in: definition) : nil }/// The plain card headed by what `record` is called (`spokenName`): a/// record read without the core's card.staticfunc named(_ record: TableRecord, in definition: TableDefinition) -> DeckCard {DeckCard(face: DefinitionCardKind.plain.rawValue, corner: nil, pressing: false, pace: nil, plate: nil, fields: ["title": .text((record.said?.slip.spoken ?? definition.name))]) }}/// Where an unreadable card is said: once per record and failure, since the/// deck reads its rows' cards on every draw.enumDeckCardLog {privatestaticlet log = Logger(subsystem: "com.cottondb.deck", category: "card")privatestaticlet said = OSAllocatedUnfairLock(initialState: Set<String>())staticfunc unreadable(_ id: String, _ failure: DeckCardFailure) {let key = "\(id)|\(failure)"guard said.withLock({ $0.insert(key).inserted }) else { return } log.fault("deck.card.unreadable:\(id, privacy: .public):\(String(describing: failure), privacy: .public)") }}