Skip to content

apple: a boxed HtmlConfig property cannot be set from Swift without a hand-written type encoding #759

Description

@andiwand

HtmlConfig.spreadsheetLimit is a TableDimensions boxed in an NSValue. Swift has no @encode, so a caller has to spell the encoding out:

config.spreadsheetLimit = withUnsafeBytes(of: TableDimensions(rows: 100_000, columns: 500)) {
    NSValue(bytes: $0.baseAddress!, objCType: "{ODRTableDimensions=II}")
}

That literal is what opendocument-app/OpenDocument.ios#185 now carries, and it is a second source of truth for the struct's layout sitting in a consumer. A field added to ODRTableDimensions breaks it silently: getValue:size: checks the size, not the encoding.

Style+Optionals.swift already solves the read half — "the ObjC layer boxes an absent std::optional as nil in an NSNumber or NSValue, which is faithful but not how Swift reads" — and its header says this is what the target exists for. There is no write half, because HtmlConfig is the only place a boxed property is settable.

Suggestion

An apple/swift/Html+Optionals.swift beside it, naming as that file does (fontColorcolor):

extension HtmlConfig {
  public var sheetLimit: TableDimensions? { get set }
  public var zoom: Double? { get set }
  // ...
}

Alternatively drop the boxing on this one property and give ODRHtmlConfig a setSpreadsheetLimit: taking the struct plus a clearSpreadsheetLimit. Less uniform, no new file.

The whole surface

property boxed as from Swift today
spreadsheetLimit NSValue / ODRTableDimensions only with the encoding literal
spreadsheetViewportMode NSNumber / enum NSNumber(value: mode.rawValue)
spreadsheetCellLimit, viewportWidth, initialZoom, pageRangeEnd NSNumber NSNumber(value:)

Only the first is actually blocked; the rest are merely not how Swift reads.

Nothing under apple/tests or apple/swift sets any of them, so the write path has no coverage either.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions