Reading from the clipboard with Swift 3 on macOS

前端 未结 5 1790
轮回少年
轮回少年 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 14:58

    Another Swift 4 Solution

    // Write to pasteboard
    let pasteboard = NSPasteboard.general
    pasteboard.declareTypes([NSPasteboard.PasteboardType.string], owner: nil)
    pasteboard.setString("Good Morning", forType: NSPasteboard.PasteboardType.string)
    
    // Read from pasteboard
    let read = pasteboard.pasteboardItems?.first?.string(forType: .string)
    

提交回复
热议问题