Swiftpack.co - dagronf/DSFBrowserView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
dagronf/DSFBrowserView
A modern-ish NSBrowser-style control allowing complex row views (macOS, Swift). Compatible back to macOS 10.11
.package(url: "https://github.com/dagronf/DSFBrowserView.git", from: "0.5.4")

DSFBrowserView

A modern-ish NSBrowser-style control allowing complex row views.

Swift Package Manager

Swift Package Manager

Why?

I use an NSBrowser for one of my apps and got frustrated with the limitations of what could be displayed within the browser columns. Well, you CAN tweak the output BUT you have to do a lot of your own drawing code in a custom NSCell. Boo!

This implementation follows the model of the modern NSTableView, using NSViews to display browser cells and allowing the user to customise the cell views depending on need.

Installation

Use Swift Package Manager.

Add https://github.com/dagronf/DSFBrowserView to your project.

Usage

You can find a basic demo in the Demos subfolder.

Creation

The basic behaviour of the control is similar to NSBrowser. Assign a delegate and provide the data when asked.

let browserView = DSFBrowserView()  // Or load from XIB

// Add columns to the browser
browserView.addColumn("Heading 1", allowMultipleSelection: false, allowEmptySelection: true)
browserView.addColumn("Heading 2", allowMultipleSelection: false, allowEmptySelection: true)
browserView.addColumn("Heading 3", allowMultipleSelection: true, allowEmptySelection: true)

// Some additional visual stuff...
browserView.autohidesScrollers = true
browserView.hideSeparators = false

// And tell the browser to update itself
browserView.reloadData()

Providing data to the control

The delegate is asked for content to display in the control.

Data Source

func rootItem(for browser: DSFBrowserView) -> Any?

Return the root element of the browser view. This might be an array of objects (for example)

func browserView(_ browser: DSFBrowserView, numberOfChildrenOfItem item: Any?) -> Int

Return the number of children for item.

func browserView(_ browser: DSFBrowserView, child index: Int, ofItem item: Any?) -> Any

Return the child item at index index for item.

func browserView(_ browser: DSFBrowserView, viewForItem item: Any?, column: Int, row: Int) -> NSView?

Return a view that represents item. Row and column are provided for informational purposes only.

Delegate

func browserView(_ browser: DSFBrowserView, selectionDidChange selections: [[Any]])

Called when the selection changes within the control.

func browserView(_ browser: DSFBrowserView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting?

Called when the user starts to drag an item within a column. Return nil to cancel the drag

Legacy (10.12 and earlier)

func browserView(_ browser: DSFBrowserView, heightOfViewForItem item: Any?) -> CGFloat

If you are targeting 10.12 or earlier, AutoLayout isn't supported for table view cells. You will need to provide a height to use for the view being displayed for item.

Screenshots

Swift Package Manager

License

MIT. Use it and abuse it for anything you want, just attribute my work. Let me know if you do use it somewhere, I'd love to hear about it!

MIT License

Copyright (c) 2021 Darren Ford

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

GitHub

link
Stars: 0
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics