{"id":16061702,"url":"https://github.com/mattmassicotte/nsui","last_synced_at":"2025-05-07T10:12:04.306Z","repository":{"id":65661102,"uuid":"596124375","full_name":"mattmassicotte/nsui","owner":"mattmassicotte","description":"AppKit and UIKit without conditional compilation","archived":false,"fork":false,"pushed_at":"2025-04-09T12:58:23.000Z","size":93,"stargazers_count":64,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-07T10:11:29.685Z","etag":null,"topics":["appkit","swift","uikit"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattmassicotte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["mattmassicotte"]}},"created_at":"2023-02-01T14:16:32.000Z","updated_at":"2025-04-30T01:38:48.000Z","dependencies_parsed_at":"2024-04-04T19:52:03.662Z","dependency_job_id":"0d070625-8a3a-4420-af29-4583a98da5f7","html_url":"https://github.com/mattmassicotte/nsui","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"09dab60e45d990922f7cad07e969ff16c3ca8be3"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmassicotte%2Fnsui","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmassicotte%2Fnsui/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmassicotte%2Fnsui/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmassicotte%2Fnsui/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattmassicotte","download_url":"https://codeload.github.com/mattmassicotte/nsui/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252856556,"owners_count":21814858,"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","swift","uikit"],"created_at":"2024-10-09T04:09:42.215Z","updated_at":"2025-05-07T10:12:04.297Z","avatar_url":"https://github.com/mattmassicotte.png","language":"Swift","funding_links":["https://github.com/sponsors/mattmassicotte"],"categories":["Project Dependency"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n[![Build Status][build status badge]][build status]\n[![Platforms][platforms badge]][platforms]\n[![Matrix][matrix badge]][matrix]\n\n\u003c/div\u003e\n\n# NSUI\nAppKit and UIKit without conditional compilation\n\nThere are small differences between otherwise-source-compatible classes in AppKit and UIKit and it drives everyone bananas. I was inspired by [Nick Lockwood](https://gist.github.com/nicklockwood/19569dc738b565c67f4d97302bf48697) to make this into a package.\n\nWhen in doubt, UIKit wins. This keeps things familiar to the most people.\n\nOther libraries you might like:\n\n- [ColorToolbox](https://github.com/raymondjavaxx/ColorToolbox): AppKit/UIKit-compatible Color abstraction and utilities\n- [KeyCodes](https://github.com/ChimeHQ/KeyCodes): AppKit Carbon key codes to UIKey-compatible enums\n\n## Integration\n\nSwift Package Manager:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/mattmassicotte/nsui\")\n]\n```\n\n## Usage\n\n```swift\n// not only does this import the NSUI package, but it also will correctly make either AppKit or UIKit accessible depending on the build target platform.\nimport NSUI\n\n// Make use of the cross-platform wrappers\nlet textView = NSUITextView()\n```\n\nThere are cases where it is necessary to provide cross-platform wrappers around functions, accessors, or initializers. These account for type differences, including cases where value differ only in optionality.\n\n```swift\n// SwiftUI\nColor(nsuiColor: NSUIColor)\nImage(nsuiImage: NSUIImage)\nNSUIControlActiveState\n\n// AppKit/UIKit\nNSUIFont.init(nsuiDescriptor:, size:)\nNSUIFontDescriptor.nsuiWithSymbolicTraits(_:)\nNSUITextView.nsuiLayoutManager\nNSUITextView.nsuiSelectedRange\n```\n\nNSUI also includes both `NSUIViewRepresentable` and `NSUIViewControllerRepresentable` to wrap your custom view subclasses.\n\n## Types\nAll Types and their `UIKit` \u0026 `AppKit` correspondance are defined in the `Aliases.swift` file. That file only defines the \nNSUI type corresponding to the proper platform. \n\nHere's the current list of types supported in NSUI: \n```\nNSUIActivityIndicatorView\nNSUIApplication\nNSUIApplicationDelegate\nNSUIApplicationDelegateAdaptor\nNSUIBezierPath\n\n// Collection Views\nNSUICollectionDataSource\nNSUICollectionView\nNSUICollectionViewItem\nNSUICollectionViewDelegate\nNSUICollectionViewLayout\nNSUICollectionViewFlowLayout\nNSUICollectionViewLayoutAttributes\nNSUICollectionViewDelegateFlowLayout\n\nNSUIButton\nNSUIColor\nNSUIEdgeInsets\nNSUIFont\nNSUIFontDescriptor\nNSUIHostingController\nNSUIImage\nNSUILongPressGestureRecognizer\nNSUINib\nNSUIPasteboard\nNSUIResponder\nNSUIStackView\nNSUIStoryboard\nNSUITableView\nNSUITableViewDiffableDataSource\nNSUITapGestureRecognizer\nNSUITextField\nNSUITextFieldDelegate\nNSUITextView\nNSUIViewController\nNSUIWorkspace\n```\n\n## Conventions\nNSUI is not a multi-platform framework to replace both UIKit and AppKit. As stated above, `NSUI` takes the stance that\nthe API from `UIKit` is the first-class citizen. However, in some cases, both AppKit and UIKit are very close to each other. \n\nLet's take, for example, the `NSProgressIndicator` and `UIActivityIndicator` classes. To start the spinning indicator view, you need to \nissue `startAnimating()` for UIKit and `startAnimation(sender:)` for AppKit.\n\nIn order to bridge that slight difference, a bridging function is created in the `Views.swift` file which looks like this: \n```swift\nextension NSUIActivityIndicator {\n    public func startAnimating() {\n        self.startAnimation(nil)\n    }\n    \n    public func stopAnimating() {\n        self.stopAnimation(nil)\n    }\n}\n```\nThis extension is wrapped within a: `#if canImport(AppKit)` and provides the `UIKit` functional equivalent to the `AppKit` class. \n\n## Enhancing `NSUI`\nIf you need to enhance `NSUI`, follow the following guidelines:\n\n1. Check if the type you need is defined in the `Aliases.swift` file.\n2. If your type needs to bridging functions, define them in a dedicated file.\n3. Prioritize `UIKit` implementations, unless type-mismatches prevent it.\n\n## Alternatives\n\n- [UXKit](https://github.com/ZeeZide/UXKit)\n\n## Contributing and Collaboration\n\nI would love to hear from you! Issues or pull requests work great. Both a [Matrix space][matrix] and [Discord][discord] are available for live help, but I have a strong bias towards answering in the form of documentation. You can also find me on [the web](https://www.massicotte.org).\n\nI prefer collaboration, and would love to find ways to work together if you have a similar project.\n\nI prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.\n\nBy participating in this project you agree to abide by the [Contributor Code of Conduct](CODE_OF_CONDUCT.md).\n\n[build status]: https://github.com/mattmassicotte/nsui/actions\n[build status badge]: https://github.com/mattmassicotte/nsui/workflows/CI/badge.svg\n[platforms]: https://swiftpackageindex.com/mattmassicotte/nsui\n[platforms badge]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmattmassicotte%2Fnsui%2Fbadge%3Ftype%3Dplatforms\n[matrix]: https://matrix.to/#/%23chimehq%3Amatrix.org\n[matrix badge]: https://img.shields.io/matrix/chimehq%3Amatrix.org?label=Matrix\n[discord]: https://discord.gg/esFpX6sErJ\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmassicotte%2Fnsui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattmassicotte%2Fnsui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmassicotte%2Fnsui/lists"}