Swiftpack.co - Schlaubischlump/SuggestionPopup as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Schlaubischlump.
Schlaubischlump/SuggestionPopup v0.0.6
A simple AppKit suggestion / autocompletion popup for macOS.
⭐️ 13
🕓 1 year ago
macOS
.package(url: "https://github.com/Schlaubischlump/SuggestionPopup.git", from: "v0.0.6")

SuggestionPopup

License: GNU Affero General Public license version 3

This is a suggestion popup implementation similar to the one used by the Maps.app on macOS 10.15. It is provided under the GNU Lesser General Public License v3.0. I only tested it on macOS 10.15, 11.0. MacOS 10.13-10.14 could work. I will test this in the future and make it compatible, if required. This software is still in beta.

Usage:
If you just want to have a simple location search, things are easy:

// Keep a reference to the search completer in memory.
var searchCompleter: LocationSearchCompleter!
...
// Somewhere in your constructor create a LocationSearchCompleter with 
// your textField. You can still use the textField delegate !
self.searchCompleter = LocationSearchCompleter(searchField: searchField)
self.searchCompleter.onShow = { ... }
self.searchCompleter.onHide = { ... }
self.searchCompleter.onHighlight = { ... }
self.searchCompleter.onSelect = { ... }

If you want a custom search, things are a little bit more difficult.

// Create or implement a new class based on NSObject which conforms
// to the `Suggestion` protocol. A simple new class could look like 
// this: 
class SimpleSuggestion: NSObject, Suggestion {
    init(title: String = "", subtitle: String = "", image: NSImage? = nil) {
        self.title = title
        self.subtitle = subtitle
        self.image = image
    }

    var title: String = ""
    var subtitle: String = ""
    var image: NSImage?
    var highlightedTitleRanges: [Range<Int>] = []
    var highlightedSubtitleRanges: [Range<Int>] = []
}
// Most of the times it might be easier to just extend your existing class.
// Take a look at the `LocationSearchCompleter` to see a simple example.


// Create a new subclass of the SearchCompleter class
class SimpleSearchCompleter: SearchCompleter {

	// This is called on `init`. It is just for your convenience.
	// Place all initial setup code here. 
	override func setup() {
	
	}

	// Override this function to prepare your search. If your search 
	// is compute intensive, use a background thread here and call
	// `setSuggestions` on completion. You might show a progress spinner
	// in this case. For a simple search, just place your code here 
	// and end the function with a `setSuggestions` call.
	override func prepareSuggestions(for searchString: String) {
		//self.showSpinner()
		super.prepareSuggestions(for: searchString)
	}
  
	// Call this function to show the search result. You might override
	// it to hide the progress spinner.
	override func setSuggestions(_ suggestions: [Suggestion]) {
		//self.hideSpinner()
		super.setSuggestions(suggestions)
	}
}

GitHub

link
Stars: 13
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Beta 3
3 years ago

Lowered swift-tools-version to 5.2.

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