Conversation
There was a problem hiding this comment.
Pull request overview
Updates cross-platform clipboard support in CopyButton and expands CI to build on iOS in addition to macOS.
Changes:
- Add conditional clipboard handling for UIKit (
UIPasteboard) vs AppKit (NSPasteboard) inCopyButton. - Rename the existing CI job to macOS-specific and add a new iOS Simulator build job in GitHub Actions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Sources/AgentLayout/Markdown/CopyButton.swift | Switches clipboard implementation to support both UIKit and AppKit. |
| .github/workflows/swift.yml | Splits macOS testing into a named job and adds an iOS build job. |
Comments suppressed due to low confidence (1)
Sources/AgentLayout/Markdown/CopyButton.swift:42
onCopied()mutates@State(copied) and callswithAnimationafter anawait, which may resume off the main actor. MarkonCopiedas@MainActor(or hop toMainActorfor the state mutations) so SwiftUI state updates and pasteboard access remain on the UI thread.
func onCopied() async {
#if canImport(UIKit)
UIPasteboard.general.string = content
#elseif canImport(AppKit)
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(content, forType: .string)
#endif
copied = true
// Wait 1.5 secs
try? await Task.sleep(for: .seconds(1.5))
withAnimation {
copied = false
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if canImport(UIKit) | ||
| UIPasteboard.general.string = content | ||
| #elseif canImport(AppKit) | ||
| let pasteboard = NSPasteboard.general | ||
| pasteboard.clearContents() | ||
| pasteboard.setString(content, forType: .string) | ||
| #endif |
There was a problem hiding this comment.
CopyButton references UIPasteboard/NSPasteboard but the file only imports SwiftUI. To ensure this compiles on both iOS and macOS, add conditional imports for UIKit/AppKit (e.g., under #if canImport(...)) before using these APIs.
| - name: Build for iOS Simulator | ||
| run: | | ||
| xcodebuild build \ | ||
| -scheme AgentKit \ | ||
| -destination 'generic/platform=iOS Simulator' \ | ||
| -skipPackagePluginValidation \ | ||
| | tail -n 20 |
There was a problem hiding this comment.
In build-ios, piping xcodebuild into tail without set -o pipefail means the step can succeed even if xcodebuild fails (the exit code will be from tail). Ensure the pipeline preserves xcodebuild's failure status (e.g., enable pipefail or avoid piping altogether).
…and AppKit