{"id":16695005,"url":"https://github.com/kyle-n/onpasteboardchange","last_synced_at":"2025-04-10T01:42:55.215Z","repository":{"id":62449570,"uuid":"313747786","full_name":"kyle-n/OnPasteboardChange","owner":"kyle-n","description":"SwiftUI View modifier that runs a callback on change to UIPasteboard or NSPasteboard","archived":false,"fork":false,"pushed_at":"2020-12-07T15:08:27.000Z","size":270,"stargazers_count":19,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-07T14:15:32.034Z","etag":null,"topics":["appkit","custom-pasteboards","ios","macos","swiftui","uikit"],"latest_commit_sha":null,"homepage":"https://cocoapods.org/pods/OnPasteboardChange","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kyle-n.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-17T21:30:12.000Z","updated_at":"2024-11-02T17:59:40.000Z","dependencies_parsed_at":"2022-11-01T23:17:02.119Z","dependency_job_id":null,"html_url":"https://github.com/kyle-n/OnPasteboardChange","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyle-n%2FOnPasteboardChange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyle-n%2FOnPasteboardChange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyle-n%2FOnPasteboardChange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyle-n%2FOnPasteboardChange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kyle-n","download_url":"https://codeload.github.com/kyle-n/OnPasteboardChange/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142296,"owners_count":21054616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appkit","custom-pasteboards","ios","macos","swiftui","uikit"],"created_at":"2024-10-12T17:04:54.108Z","updated_at":"2025-04-10T01:42:55.195Z","avatar_url":"https://github.com/kyle-n.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OnPasteboardChange\n\nA SwiftUI View modifier that triggers a callback whenever the pasteboard changes. Works with UIKit and AppKit - perfect for cross-platform SwiftUI projects.\n\n## Installation\n\nSupports iOS 14.0+ and macOS 11.0+.\n\n### Swift Package Manager\n\nIn Xcode, File -\u003e Swift Packages -\u003e Add Package Dependency... and paste `https://github.com/kyle-n/OnPasteboardChange`.\n\n### CocoaPods\n\nAdd `pod OnPasteboardChange` to your `Podfile` and run `pod install` in your project directory.\n\n## Usage\n\n```swift\nimport OnPasteboardChange\n\nstruct ContentView: View {\n    @State private var text: String = \"\"\n    \n    var body: some View {\n        VStack {\n            TextEditor(text: $text)\n                .padding()\n                .onPasteboardChange {\n                    print(\"The clipboard was changed!\")\n                    let latestItem = UIPasteboard.general.items.first\n                }\n        }\n    }\n}\n```\n\nAll this modifier does is alert your code the pasteboard has changed. Your code can then check the pasteboard, read from it, write to it or do anything you like. This way, your code can control when to check the clipboard (and when to trigger the iOS 14 \"X app pasted from Y app\" alert).\n\nThe modifier will pick up changes to the pasteboard while the app is in the background. This works on iOS and macOS. \n\n### Custom pasteboards\n\nBy default, `.onPasteboardChange` will watch `UIPasteboard.general` or `NSPasteboard.general` for changes. However, if you have a custom pasteboard, you can track changes on that as well. \n\n```swift\nimport OnPasteboardChange\n\nstruct ContentView: View {\n    @State private var text: String = \"\"\n    \n    let pb = UIPasteboard.withUniqueName()\n    \n    var body: some View {\n        VStack {\n            Button(\"Add to Custom Pasteboard\") {\n                pb.addItems([[\"newItem\": \"value\"]])\n            }\n            TextEditor(text: $text)\n                .padding()\n                .onPasteboardChange(for: pb) {\n                    // only triggered after pressing \"Add to Custom Pasteboard\"\n                    print(\"custom pb changed\")\n                }\n        }\n    }\n}\n```\n\n## Credits\n\nCreated by [Kyle Nazario](https://twitter.com/kbn_au).\n\n\u003cimg align=\"middle\" src=\"https://github.com/kyle-n/OnPasteboardChange/raw/main/Tests/clippy.png\" alt=\"Clippy wants to help you read UIPasteboard\"\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyle-n%2Fonpasteboardchange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyle-n%2Fonpasteboardchange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyle-n%2Fonpasteboardchange/lists"}