- July 26, 2025
- Mins Read
pod ‘DMSwipeCards’
First import the module:
import DMSwipeCards
Next create an instance of a DMSwipeCardsView
:
(Element
can be your custom model, or just String
)
let swipeView = DMSwipeCardsView<Element>(frame: frame,
viewGenerator: viewGenerator,
overlayGenerator: overlayGenerator)
Views get loaded lazy, so you have to provide DMSwipeCardsView
with a ViewGenerator and optionally an OverlayGenerator.
let viewGenerator: (String, CGRect) -> (UIView) = { (element: Element, frame: CGRect) -> (UIView) in
// return a UIView here
}
let overlayGenerator: (SwipeMode, CGRect) -> (UIView) = { (mode: SwipeMode, frame: CGRect) -> (UIView) in
// return a UIView here
}
To add new cards, just call the addCards
method with an array of the previously defined Element
:
swipeView.addCards([Element], onTop: true)
DMSwipeCardsView
has a delegate property so you can get informed when a card has been swipped. The delegate has to implement following methods:
func swipedLeft(_ object: Any)
func swipedRight(_ object: Any)
func cardTapped(_ object: Any)
func reachedEndOfStack()
The object
parameter is guarenteed to have the type Element
. Sadly generics don’t work here.
For a nice working demo sample, please take a look the Example project.
To run the example, first run pod install
in the Example
directory.
NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. 💻 Installation 📦 Swift Package Manager Using Swift Package Manager, add ...
An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation. NavigationStack Installation ...
With SwiftUI Router you can power your SwiftUI app with path-based routing. By utilizing a path-based system, navigation in your app becomes ...
This package takes SwiftUI's familiar and powerful NavigationStack API and gives it superpowers, allowing you to use the same API not just ...