Created
January 11, 2015 00:58
-
-
Save kristopherjohnson/f301434cdecc28950041 to your computer and use it in GitHub Desktop.
Utility functions to copy/paste text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
#if os(iOS) | |
import UIKit | |
#else | |
import AppKit | |
#endif | |
/// Return string value currently on clipboard | |
func getPasteboardContents() -> String? { | |
#if os(iOS) | |
let pasteboard = UIPasteboard.generalPasteboard() | |
return pasteboard.string | |
#else | |
let pasteboard = NSPasteboard.generalPasteboard() | |
return pasteboard.stringForType(NSPasteboardTypeString) | |
#endif | |
} | |
/// Write a string value to the pasteboard | |
func copyToPasteboard(text: String) { | |
#if os(iOS) | |
let pasteboard = UIPasteboard.generalPasteboard() | |
pasteboard.string = text | |
#else | |
let pasteboard = NSPasteboard.generalPasteboard() | |
pasteboard.clearContents() | |
pasteboard.setString(text, forType: NSPasteboardTypeString) | |
#endif | |
} |
wow the clearContents()
part is exactly what i needed. It won't work without it. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks