Skip to content

Commit

Permalink
📄 Copy method for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
benlmyers committed Sep 19, 2022
1 parent c6a9962 commit 520ca2d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Sources/FoundationPlus/Extensions/Swift/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,23 @@ public extension String {
return self.components(separatedBy: CharacterSet.alphanumerics.union(otherSet).inverted).joined()
}
}

#if canImport(SwiftUI)
import SwiftUI

public extension String {

/**
Copies the string to the user's clipboard.
*/
func copyToClipboard() {
#if os(iOS)
UIPasteboard.general.string = self
#else
let pasteboard = NSPasteboard.general
pasteboard.declareTypes([.string], owner: nil)
pasteboard.setString(self, forType: .string)
#endif
}
}
#endif

0 comments on commit 520ca2d

Please sign in to comment.