
Welcome to TikTok Clone
A production-ready iOS TikTok clone built with Swift for the frontend and Firebase for the backend. This project replicates both the Chinese (Douyin) and U.S. versions of TikTok, featuring smooth video playback, advanced caching strategies, and a complete social media experience.Key Features
Full-Screen Video Feed
Infinite scroll with paginated loading, smooth transitions, and automatic playback management
Video Recording & Upload
Record videos with AVFoundation, upload to Firebase Storage, and publish to Firestore
Two-Level Video Caching
Memory + disk caching with SHA-2 encryption for optimal performance and offline support
User Profiles
Stretchy headers, video grids, and profile customization with animated backgrounds
Social Interactions
Likes, comments, shares, and real-time engagement tracking
MVVM Architecture
Clean separation of concerns with RxSwift for reactive data binding
Video Playback
The home feed uses aUITableView with full-screen cells, each containing an AVPlayer for smooth video playback. Videos are pre-fetched and cached to ensure seamless scrolling.
HomeViewController.swift:73-80
The table view uses paging to snap to full-screen videos, mimicking TikTok’s signature scrolling behavior.
Video Upload
Videos are recorded usingAVCaptureSession, saved locally, and uploaded to Firebase Storage. The download URL is then stored in Firestore along with post metadata.
VideoPostRequest.swift:37-52
Caching System
TheVideoCacheManager implements a sophisticated two-level caching strategy:
- Memory Cache: Using
NSCachefor instant access to recently viewed videos - Disk Cache: File-based storage with SHA-2 encrypted filenames for security
VideoCacheManager.swift:76-85
Cache queries follow a waterfall pattern: memory → disk → Firebase download
User Profiles
Profile pages feature a stretchy header effect that scales when pulled down, implemented with customUICollectionViewFlowLayout.
ProfileViewController.swift:159-163
Social Features
The app includes a complete social layer with:- Likes & Shares: Real-time counters stored in Firestore
- Comments: Pop-up view with
UITableViewfor threaded discussions - User Interactions: Profile navigation, follow/unfollow functionality
Post.swift:13-27
Architecture
The app follows MVVM (Model-View-ViewModel) architecture with RxSwift for reactive programming:- Models:
Post,User,Commentstructs with Codable conformance - Views: UIKit components with programmatic layouts using SnapKit
- ViewModels: Business logic with RxSwift observables for data binding
HomeViewModel.swift:20-22
Tech Stack
Swift
Modern Swift 5+ with UIKit for UI development
Firebase
Firestore for database, Storage for videos, Analytics for tracking
RxSwift
Reactive programming for clean data flow and binding
SnapKit
DSL for programmatic Auto Layout constraints
Lottie
Beautiful loading animations and micro-interactions
AVFoundation
Video recording, playback, and processing
Get Started
Ready to build and run the app? Follow these guides to set up your development environment:Installation
Install dependencies, set up Xcode, and build the project
Firebase Setup
Configure Firebase services: Storage, Firestore, and Analytics
Project Structure
Open Source
This project is open source and available on GitHub. Feel free to explore the code, report issues, or contribute improvements!This is an educational project demonstrating iOS development best practices. Some features are simplified for learning purposes.
