maydibee/swiftyfilters
---
π Features
- 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.
π¦ Installation
Swift Package Manager
- 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.
Manual Setup
Add SwiftyFilters as a dependency in your Package.swift:
dependencies: [
.package(url: "https://github.com/maydibee/SwiftyFilters.git", from: "1.0.0")
]Quick start
The basic usage of SwiftyFilters, when custom UI elements for filters are not required, consists of four steps.
1. Define the root filter and implement filter components in the body
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)
}
}
}
2. Initialize SFFiltersCore and pass the AircraftFilter instance to the content parameter
let filter = AircraftFilter(worker: worker)
let filtersCore = SFFiltersCore<Aircraft>(title: "Filters", content: filter)
3. Initialize SFFilterRootView with the created filtersCore and present it where needed
SFFilterRootView(filtersCore: filtersCore)4. Apply filters on demand
func applyFilters() {
self.filteredAircraft = filtersCore.getFilteredData(from: aircraft)
}π Documentation
Read the full documentation here: π SwiftyFilters Documentation
π Usage
Package Metadata
Repository: maydibee/swiftyfilters
Default branch: main
README: README.md