I wanted to learn how to do an iOS application, and I found this tutorial: SwiftUI Course for Beginners β Create an iOS App from Scratch. It really helped me to understand fundamental SwiftUI concepts, API integration, and modern iOS development patterns.
You will have more information below about what I learned in this tutorial (it was made by AI).
iOS Movie App is a feature-rich movie and TV show discovery application that leverages The Movie Database (TMDB) API to provide users with trending content, search functionality, and detailed media information. Built entirely with SwiftUI, it showcases clean architecture and modern iOS development practices.
- Home Screen: Displays trending movies and TV shows with a hero section
- Search: Real-time search across movies and TV shows with toggle functionality
- Details: Comprehensive movie/TV show information with integrated YouTube trailers
- Downloads: Local storage for favorite content using SwiftData
- Upcoming: Preview of upcoming releases
- SwiftUI Navigation: Modern NavigationStack with programmatic navigation
- Async/Await: Modern concurrency for API calls
- SwiftData Integration: Local data persistence for downloads
- YouTube Integration: Embedded trailer playback
- Responsive Design: Adaptive layouts using GeometryReader
- Error Handling: Comprehensive error states and user feedback
- Search Debouncing: Optimized search with 500ms delay
This project follows the MVVM architectural pattern which provides a clear separation of concerns and improves code maintainability, testability, and scalability.
The model layer represents the data structures and business logic:
-
Title: Core data model using SwiftData's@Modelmacro- Implements
Decodablefor API response parsing - Includes both movie and TV show properties (
title/name) - Uses
@Attribute(.unique)for data integrity - Provides preview data for SwiftUI previews
- Implements
-
TMDBAPIObject: Wrapper for TMDB API responses- Contains array of
Titleresults - Handles API pagination structure
- Contains array of
-
YoutubeSearchResponse: YouTube API response model- Decodes video IDs for trailer playback
- Nested structure following YouTube API format
SwiftUI views are purely declarative and focus on UI presentation:
- Reactive UI: Views automatically update when ViewModels change
- State Management: Uses
@Observablemacro for automatic UI updates - Navigation: Modern NavigationStack with type-safe routing
- Reusable Components:
HorizontalListView,VerticalListView - Error Handling: Dedicated error states in UI
// Example of reactive view binding
struct HomeView: View {
let viewModel = ViewModel()
var body: some View {
// UI automatically updates when viewModel.homeStatus changes
switch viewModel.homeStatus {
case .fetching:
ProgressView()
case .success:
// Display content
case .failure(let error):
Text(error.localizedDescription)
}
}
}ViewModels act as the bridge between Views and Models, handling business logic:
-
ViewModel: Main home screen logic- State Management: Uses
@Observablefor reactive updates - Status Tracking: Custom
FetchStatusenum for loading states - Concurrent Operations: Async/await with parallel API calls
- Data Caching: Prevents unnecessary API calls
- State Management: Uses
-
SearchViewModel: Search functionality- Real-time Search: Debounced search implementation
- Error Handling: User-friendly error messages
- State Isolation: Independent from main ViewModel
// Example of ViewModel with proper state management
@Observable
class ViewModel {
enum FetchStatus {
case notStarted, fetching, success
case failure(underlyingError: Error)
}
private(set) var homeStatus: FetchStatus = .notStarted
func getTitles() async {
homeStatus = .fetching
// Parallel API calls for better performance
async let tMovies = dataFetcher.fetchTitles(for: "movie", by: "trending")
async let tTV = dataFetcher.fetchTitles(for: "tv", by: "trending")
// Handle results...
}
}Services handle external dependencies and data operations:
-
DataFetcher: Repository pattern implementation- Generic Networking: Reusable
fetchAndDecodemethod - URL Building: Dynamic endpoint construction
- Error Handling: Custom
NetworkErrortypes - API Integration: TMDB and YouTube API handling
- Generic Networking: Reusable
-
APIConfig: Configuration management- Environment Variables: Secure API key handling
- Dependency Injection: Centralized configuration
-
Separation of Concerns
- Views focus solely on UI presentation
- ViewModels handle business logic and state
- Models represent data without UI dependencies
-
Testability
- ViewModels can be unit tested independently
- Mock services can be injected for testing
- Business logic is isolated from UI
-
Reusability
- ViewModels can be shared across different views
- Generic services work with multiple data types
- Modular components for different screens
-
Maintainability
- Clear code organization and responsibilities
- Easy to modify business logic without affecting UI
- Scalable for future feature additions
-
SwiftUI Integration
- Natural fit with SwiftUI's reactive paradigm
@Observableprovides automatic UI updates- Clean data flow from service β ViewModel β View
- Models:
Title,TMDBAPIObject,YoutubeSearchResponse - ViewModels:
ViewModel,SearchViewModel - Views: Modular SwiftUI views with reusable components
- Services:
DataFetcher,APIConfig
- Framework: SwiftUI
- Language: Swift
- Persistence: SwiftData
- Networking: URLSession with async/await
- Architecture: MVVM
- APIs: TMDB API, YouTube Data API
- iOS 17.0+
- Xcode 15.0+
- Swift 5.9+
- Valid TMDB API key from The Movie Database
- YouTube Data API key from Google Cloud Console
-
Clone the repository
git clone https://github.com/ZifFiji/iOS-Movie-App.git cd iOS-Movie-App -
Configure API Keys
cd my-app cp APIConfig.json.example APIConfig.jsonEdit
APIConfig.jsonwith your API keys:{ "tmdbBaseURL": "https://api.themoviedb.org", "tmdbAPIKey": "YOUR_TMDB_API_KEY", "youtubeBaseURL": "https://youtube.com/embed", "youtubeAPIKey": "YOUR_YOUTUBE_API_KEY", "youtubeSearchURL": "https://www.googleapis.com/youtube/v3/search" } -
Open and Run
- Open
my-app.xcodeprojin Xcode - Select your target device or simulator
- Build and run (β+R)
- Open
The app features a modern tab-based interface with:
- Home: Hero image with trending content sections
- Upcoming: Preview of upcoming releases
- Search: Grid-based search with movie/TV toggle
- Downloads: Locally saved content
This project demonstrates proficiency in:
- Declarative UI development
- State management with
@State,@Environment - Navigation with NavigationStack and NavigationPath
- Custom modifiers and reusable components
- MVVM architecture implementation
- Async/await networking patterns
- Error handling and user feedback
- Local data persistence with SwiftData
- RESTful API consumption
- JSON decoding with Codable
- Image loading and caching
- Real-time search implementation
- Structured concurrency
- Swift Package Manager integration
- Type-safe navigation
- Property wrappers
This project was built following a comprehensive iOS development tutorial, serving as a practical implementation of SwiftUI fundamentals and modern iOS development practices. The tutorial provided excellent guidance on:
- SwiftUI basics and advanced concepts
- API integration patterns
- Navigation and state management
- Data persistence strategies
- Modern Swift language features