As asked
Design the full iOS client-side architecture for a photo feed that loads images lazily, supports pull-to-refresh, infinite scroll, offline caching, and maintains scroll position after backgrounding. Walk me through every layer.
Sample answer outline
A strong answer covers: UICollectionView with diffable data source for the list, a ViewModel layer (ObservableObject or @Observable) holding paginated posts, a repository abstraction backed by an in-memory cache plus SQLite (via Core Data or GRDB) for offline, a URLSession-based image fetcher with disk and memory NSCache layers, prefetching via UICollectionViewDataSourcePrefetching, and saving scroll offset to scene state restoration. Should mention image decoding off the main thread.
Expect these follow-ups
- How would you handle conflicting cached data when the same post appears in multiple feeds?
- What changes when the feed must also support video cells that autoplay on scroll?