Never has creating complex filters in iOS apps been so effortless. Magic is here β¨
SwiftyFilters is a lightweight, pure-Swift framework that lets you create complex filter systems using a DSL-like syntaxβ-βthink SwiftUI, but for filtering.
The secret? A SwiftUI-inspired syntax that transforms tedious filtering logic into clean, expressive code. Whether you're filtering aircraft by type, products by price, or events by date, SwiftyFilters lets you focus on what you want to achieve, while it handles the how.
Built with performance in mind, SwiftyFilters uses lazy-loading at every level to ensure your app stays fast and responsive. It only loads data and allocates resources when theyβre actually needed.
- Declarative API: Define filters using a SwiftUI-like syntax.
- Nested Filters: Create complex filter hierarchies with ease.
- Lazy Loading: Resources are loaded only when needed.
- SwiftUI Integration: Designed to work seamlessly with SwiftUI.
- Customizable: Use default UI components or build your own.
- In Xcode, open your project and navigate to File β Add Packages....
- Paste the repository URL: https://github.com/maydibee/SwiftyFilters.git
- Select the version you want to use (or leave as "Up to Next Major").
- Click Add Package.
Add SwiftyFilters as a dependency in your Package.swift
:
dependencies: [
.package(url: "https://github.com/maydibee/SwiftyFilters.git", from: "1.0.0")
]
The basic usage of SwiftyFilters, when custom UI elements for filters are not required, consists of four steps.
struct AircraftFilter: SFFilter {
let worker: AircraftListWorker
var body: [SFFilterComponent<Aircraft>] {
SFMultiSelectionFilter(title: "Type")
.fetchItems { await worker.fetchAllTypes() }
.filter(by: \.type)
SFMultiSelectionFilter(title: "Last exploiter")
.fetchItems { await self.worker.fetchAllExploiters() }
.filter(byOptional: \.lastExploater)
.includeNone(withTitle: "New aircraft")
SFKeywordsFilter(title: "Remarks")
.filter(by: \.remarks)
.includeNone(withTitle: "No remarks")
SFRangeFilter(title: "First flight date")
.filter(by: \.firstFlightDate)
.displayIn { node in
SFFilterDateRangeView(node: node)
}
}
}
let filter = AircraftFilter(worker: worker)
let filtersCore = SFFiltersCore<Aircraft>(title: "Filters", content: filter)
SFFilterRootView(filtersCore: filtersCore)
func applyFilters() {
self.filteredAircraft = filtersCore.getFilteredData(from: aircraft)
}
Read the full documentation here:
π SwiftyFilters Documentation
π Usage