Reading from the clipboard with Swift 3 on macOS

前端 未结 5 1787
轮回少年
轮回少年 2021-02-07 14:44

I\'m a beginner with Swift, and I\'m trying to figure out how can I read what has been copied to the clipboard On macOS (Swift 3)? I\'ve searched a lot but can\'t seem to find a

5条回答
  •  被撕碎了的回忆
    2021-02-07 15:10

    Times have changed. In Swift 3+ you would do it like this: (if you are only interested in strings)

    func clipboardContent() -> String?
    {
        return NSPasteboard.general.pasteboardItems?.first?.string(forType: .string)
    }
    

提交回复
热议问题