Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 18, 2025

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Swift compile fails during CI with: "value of optional type 'Date?' must be unwrapped to a value of type 'Date'" in Sources/prosign/views/CertificateView.swift. The root cause is that certExpiries is declared as [String: Date?], so a lookup returns an optional Date? (i.e., Date??). The code passes that lookup directly to expiryDisplay(for:) and force-unwraps expiry in certificateBackground(for:), causing a compile error and unsafe force-unwraps.

Make the following safe, minimal changes to fix the compile error and avoid force-unwraps:

  1. In certificateContent(for:), unwrap the dictionary lookup and the inner optional Date before calling expiryDisplay(for:). Replace the block

    if let expiry = certExpiries[cert.folderName] {
    expiryDisplay(for: expiry)
    } else {
    Text("No expiry date")
    .font(.caption)
    .fontWeight(.medium)
    .foregroundColor(.secondary)
    }

with:

if let expiryOptional = certExpiries[cert.folderName],
   let expiry = expiryOptional {
    expiryDisplay(for: expiry)
} else {
    Text("No expiry date")
        .font(.caption)
        .fontWeight(.medium)
        .foregroundColor(.secondary)
}
  1. In certificateBackground(for:), remove force-unwrap and safely bind the inner optional. Replace:

    guard let expiry = certExpiries[cert.folderName], expiry != nil else {
    return Color.clear
    }
    let now = Date()
    let components = Calendar.current.dateComponents([.day], from: now, to: expiry!)
    let days = components.day ?? 0

with:

guard let expiryOptional = certExpiries[cert.folderName],
      let expiry = expiryOptional else {
    return Color.clear
}
let now = Date()
let components = Calendar.current.dateComponents([.day], from: now, to: expiry)
let days = components.day ?? 0

No other functional changes are required. Keep file formatting and surrounding code unchanged. Commit the change and open a pull request with a concise title and description referencing the CI failure and this fix.

Files to modify:

  • Sources/prosign/views/CertificateView.swift

Make sure the PR includes the updated file content and a helpful PR description explaining the fix and how it resolves the CI compile error.

This pull request was created as a result of the following prompt from Copilot chat.

Swift compile fails during CI with: "value of optional type 'Date?' must be unwrapped to a value of type 'Date'" in Sources/prosign/views/CertificateView.swift. The root cause is that certExpiries is declared as [String: Date?], so a lookup returns an optional Date? (i.e., Date??). The code passes that lookup directly to expiryDisplay(for:) and force-unwraps expiry in certificateBackground(for:), causing a compile error and unsafe force-unwraps.

Make the following safe, minimal changes to fix the compile error and avoid force-unwraps:

  1. In certificateContent(for:), unwrap the dictionary lookup and the inner optional Date before calling expiryDisplay(for:). Replace the block

    if let expiry = certExpiries[cert.folderName] {
    expiryDisplay(for: expiry)
    } else {
    Text("No expiry date")
    .font(.caption)
    .fontWeight(.medium)
    .foregroundColor(.secondary)
    }

with:

if let expiryOptional = certExpiries[cert.folderName],
   let expiry = expiryOptional {
    expiryDisplay(for: expiry)
} else {
    Text("No expiry date")
        .font(.caption)
        .fontWeight(.medium)
        .foregroundColor(.secondary)
}
  1. In certificateBackground(for:), remove force-unwrap and safely bind the inner optional. Replace:

    guard let expiry = certExpiries[cert.folderName], expiry != nil else {
    return Color.clear
    }
    let now = Date()
    let components = Calendar.current.dateComponents([.day], from: now, to: expiry!)
    let days = components.day ?? 0

with:

guard let expiryOptional = certExpiries[cert.folderName],
      let expiry = expiryOptional else {
    return Color.clear
}
let now = Date()
let components = Calendar.current.dateComponents([.day], from: now, to: expiry)
let days = components.day ?? 0

No other functional changes are required. Keep file formatting and surrounding code unchanged. Commit the change and open a pull request with a concise title and description referencing the CI failure and this fix.

Files to modify:

  • Sources/prosign/views/CertificateView.swift

Make sure the PR includes the updated file content and a helpful PR description explaining the fix and how it resolves the CI compile error.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@NovaDev404 NovaDev404 closed this Oct 18, 2025
@NovaDev404 NovaDev404 deleted the copilot/fix-date-optional-unwrapping branch October 18, 2025 00:35
Copilot AI requested a review from NovaDev404 October 18, 2025 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants