{"id":13674876,"url":"https://github.com/RoyalIcing/BurntCocoaUI","last_synced_at":"2025-04-28T19:31:43.335Z","repository":{"id":32018469,"uuid":"35589649","full_name":"RoyalIcing/BurntCocoaUI","owner":"RoyalIcing","description":"Use Swift enums and structs with NSMenu, NSPopUpButton, NSSegmentedControl","archived":false,"fork":false,"pushed_at":"2019-11-15T02:51:02.000Z","size":59,"stargazers_count":31,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T18:22:59.057Z","etag":null,"topics":["mac","macos","nsmenu","swift","swift-enum"],"latest_commit_sha":null,"homepage":"","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/RoyalIcing.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":"2015-05-14T03:54:11.000Z","updated_at":"2024-03-20T07:01:16.000Z","dependencies_parsed_at":"2022-08-24T14:22:41.452Z","dependency_job_id":null,"html_url":"https://github.com/RoyalIcing/BurntCocoaUI","commit_stats":null,"previous_names":["burntcaramel/burntcocoaui"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2FBurntCocoaUI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2FBurntCocoaUI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2FBurntCocoaUI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2FBurntCocoaUI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RoyalIcing","download_url":"https://codeload.github.com/RoyalIcing/BurntCocoaUI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251375411,"owners_count":21579440,"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":["mac","macos","nsmenu","swift","swift-enum"],"created_at":"2024-08-02T12:00:17.554Z","updated_at":"2025-04-28T19:31:43.092Z","avatar_url":"https://github.com/RoyalIcing.png","language":"Swift","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# BurntCocoaUI\nDeclarative assistants to make NSMenu, NSPopUpButton, NSSegmentedControl easier. Use Swift enums instead of creating and removing NSMenuItems and fiddling with indexes and tags.\n\n## Example\n\n### NSPopUpMenu with PopUpButtonAssistant\n\n#### The choices you want to show in the menu, as an enum.\n\n```swift\nenum BaseContentTypeChoice: Int {\n\tcase LocalHTMLPages = 1\n\tcase Images\n\tcase Feeds\n}\n```\n\n#### Add an extension to the enum to make it conform to the UIChoiceRepresentative protocol.\n\n```swift\nextension BaseContentTypeChoice: UIChoiceRepresentative {\n\tvar title: String {\n\t\tswitch self {\n\t\tcase .LocalHTMLPages:\n\t\t\treturn \"Local Pages\"\n\t\tcase .Images:\n\t\t\treturn \"Images\"\n\t\tcase .Feeds:\n\t\t\treturn \"Feeds\"\n\t\t}\n\t}\n\t\n\ttypealias UniqueIdentifier = BaseContentTypeChoice\n\tvar uniqueIdentifier: UniqueIdentifier { return self }\n}\n```\n\n#### Use PopUpButtonAssistant in View Controller, with customized menu item titles.\n\n```swift\nclass ExampleViewController: NSViewController {\n  \n\t@IBOutlet var baseContentTypeChoicePopUpButton: NSPopUpButton! // Hooked up in storyboard/nib\n\tvar baseContentTypeChoicePopUpButtonAssistant: PopUpButtonAssistant\u003cBaseContentTypeChoice\u003e!\n\n\tvar chosenBaseContentChoice: BaseContentTypeChoice = .LocalHTMLPages\n\t\n\n\tvar baseContentTypeChoiceMenuItemRepresentatives: [BaseContentTypeChoice?] {\n\t\treturn [\n\t\t\t.LocalHTMLPages,\n\t\t\t.Images,\n\t\t\t.Feeds\n\t\t]\n\t}\n\t\n\tfunc updateBaseContentTypeChoiceUI() {\n\t\tlet popUpButtonAssistant = baseContentTypeChoicePopUpButtonAssistant ?? {\n\t\t\tlet popUpButtonAssistant = PopUpButtonAssistant\u003cBaseContentTypeChoice\u003e(popUpButton: baseContentTypeChoicePopUpButton)\n\t\t\t\n\t\t\tlet menuAssistant = popUpButtonAssistant.menuAssistant\n\t\t\t// Customize the title by appending a total count\n\t\t\tmenuAssistant.customization.title = { choice in\n\t\t\t\tlet baseContentType = choice.baseContentType\n\t\t\t\tlet loadedURLCount = self.pageMapper?.numberOfLoadedURLsWithBaseContentType(baseContentType) ?? 0\n\t\t\t\treturn \"\\(choice.title) (\\(loadedURLCount))\"\n\t\t\t}\n\t\t\t\n\t\t\tself.baseContentTypeChoicePopUpButtonAssistant = popUpButtonAssistant\n\t\t\treturn popUpButtonAssistant\n\t\t}()\n\t\t\n\t\tpopUpButtonAssistant.menuItemRepresentatives = baseContentTypeChoiceMenuItemRepresentatives\n\t\tpopUpButtonAssistant.update()\n\t}\n\t\n\t@IBAction func changeBaseContentTypeFilter(sender: NSPopUpButton) {\n\t\tif let contentChoice = baseContentTypeChoicePopUpButtonAssistant.selectedItemRepresentative {\n\t\t\tchosenBaseContentChoice = contentChoice\n\t\t\t\n\t\t\treloadData()\n\t\t}\n\t}\n\t\n\tfunc reloadData() {\n\t\t// Example ...\n\t}\n}\n```\n\n## Installation\n\nTo integrate into your Xcode project using Carthage, specify it in your Cartfile:\n\n```\ngithub \"BurntCaramel/BurntCocoaUI\" \u003e= 0.3\n```\n\n## Origin\nMy Mac app Lantern: http://www.burntcaramel.com/lantern/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRoyalIcing%2FBurntCocoaUI","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRoyalIcing%2FBurntCocoaUI","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRoyalIcing%2FBurntCocoaUI/lists"}