This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
CardsViewController is an iOS Swift library providing a swipeable card stack UI component (Tinder-style). Distributed via CocoaPods and Swift Package Manager. No external dependencies — UIKit only.
- Swift 5.0, iOS 11.0+
- License: MIT
- Current version: 1.3.0 (see
CardsViewController.podspec)
The library is distributed via Swift Package Manager. The Example app is in Example/.
# Open the Example project (no pod install needed — uses local SPM package)
open Example/CardsViewController.xcodeprojThe Example project references the library as a local SPM package (XCLocalSwiftPackageReference ".."), so changes to Sources/ are picked up automatically.
Build: select the CardsViewController_Example scheme in Xcode, then Build (Cmd+B).
Tests: Example/Tests/Tests.swift — run via Xcode (Cmd+U) on the CardsViewController_Tests target. Test scaffolding is minimal.
CLI build (if needed):
xcodebuild -project Example/CardsViewController.xcodeproj \
-scheme CardsViewController_Example \
-destination 'platform=iOS Simulator,name=iPhone 16' \
buildDelegate-DataSource pattern (like UITableView). The library lives in Sources/CardsViewController/.
CardsViewController— Main container view controller. Manages a stack of child view controllers as cards. Only keepsvisibleCardsCount(default 3) cards in memory.CardViewControllerprotocol — Each card conforms to this. ProvidesfrontView, optionalbackViewfor flip animation.CardsViewControllerDatasource— Provides card count, card view controllers, optional decoration views and transforms.CardsViewControllerDelegate— Handles swipe/tap animations, progress tracking, card lifecycle events. All methods have defaults viaTypes+Defaults.swift.
SwipeDirection:.up,.down,.left,.rightSwipeAnimation:.none,.putAtTheEnd,.throwOutTapAnimation:.none,.flip
Card struct tracks each card's state (.inStack, .dragging, .cancelAnimation, .removingAnimation, .transformAnimation), its absolute index in the data vs visible z-order index, and its animator.
Uses UIViewPropertyAnimator for interruptible animations. Three animation types as separate structs:
ThrowOutAnimation— card flies off screenCancelAnimation— spring animation returning card to positionShakeAnimation— sequential left-right-center shake
AnimationHelpers provides direction calculation from velocity, translation for off-screen throw, default stacking transforms, and predefined velocities for programmatic swipes.
LayoutGuideprotocol — unifiesUIViewandUILayoutGuidefor constraint handlingUIViewController+Child— child view controller add/remove helpersCGPoint+Operators— vector math operators (+, -, *, /)