ios-performance-battery-patternslisted
Install: claude install-skill patrickserrano/lacquer
# Battery & Performance Patterns
Apply these whenever touching widgets, animations, networking, or background work.
## Widgets
- Limit `Timeline` entries to **≤ 2** (current + one next-day refresh). More entries run the provider repeatedly and drain battery.
- Use `.atEnd` reload policy — let WidgetKit decide when to refresh.
## Animations
- Always stop animations in `.onDisappear`. Animations left running off-screen still consume CPU/GPU.
- Bind repeating animations to a `@State var isAnimating = false`: set `true` in `.onAppear`, `false` in `.onDisappear`, and pass `value: isAnimating` to `withAnimation`.
- Use `.repeatCount(N)` instead of `.repeatForever` for attention animations.
## Low Power Mode
Guard expensive operations before they start:
```swift
guard !ProcessInfo.processInfo.isLowPowerModeEnabled else { return }
```
Apply to: image preloading, background downloads, video prefetch, heavy sync.
## Network
```swift
let config = URLSessionConfiguration.default
config.allowsConstrainedNetworkAccess = false // respect Low Data Mode
config.allowsExpensiveNetworkAccess = false // avoid cellular when Wi-Fi preferred
config.waitsForConnectivity = true // queue rather than fail when offline
```
## Observer & Task Cleanup
`@Observable` macro-generated storage prevents `nonisolated deinit` from removing `NotificationCenter` observers. Use reference-type boxes instead:
```swift
final class NotificationObserverBox {
private var tokens: [NSObjectPro