Skip to content

ZifFiji/iOS-Movie-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

iOS Movie App

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).

πŸ“± Overview

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.

✨ Features

🎬 Core Functionality

  • 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

πŸ›  Technical Features

  • 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

πŸ— Architecture

MVVM (Model-View-ViewModel) Implementation

This project follows the MVVM architectural pattern which provides a clear separation of concerns and improves code maintainability, testability, and scalability.

πŸ“Š Model Layer

The model layer represents the data structures and business logic:

  • Title: Core data model using SwiftData's @Model macro

    • Implements Decodable for API response parsing
    • Includes both movie and TV show properties (title/name)
    • Uses @Attribute(.unique) for data integrity
    • Provides preview data for SwiftUI previews
  • TMDBAPIObject: Wrapper for TMDB API responses

    • Contains array of Title results
    • Handles API pagination structure
  • YoutubeSearchResponse: YouTube API response model

    • Decodes video IDs for trailer playback
    • Nested structure following YouTube API format

🎭 View Layer (SwiftUI)

SwiftUI views are purely declarative and focus on UI presentation:

  • Reactive UI: Views automatically update when ViewModels change
  • State Management: Uses @Observable macro 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)
        }
    }
}

🧠 ViewModel Layer

ViewModels act as the bridge between Views and Models, handling business logic:

  • ViewModel: Main home screen logic

    • State Management: Uses @Observable for reactive updates
    • Status Tracking: Custom FetchStatus enum for loading states
    • Concurrent Operations: Async/await with parallel API calls
    • Data Caching: Prevents unnecessary API calls
  • 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...
    }
}

πŸ”§ Service Layer

Services handle external dependencies and data operations:

  • DataFetcher: Repository pattern implementation

    • Generic Networking: Reusable fetchAndDecode method
    • URL Building: Dynamic endpoint construction
    • Error Handling: Custom NetworkError types
    • API Integration: TMDB and YouTube API handling
  • APIConfig: Configuration management

    • Environment Variables: Secure API key handling
    • Dependency Injection: Centralized configuration

🎯 MVVM Benefits in This Project

  1. Separation of Concerns

    • Views focus solely on UI presentation
    • ViewModels handle business logic and state
    • Models represent data without UI dependencies
  2. Testability

    • ViewModels can be unit tested independently
    • Mock services can be injected for testing
    • Business logic is isolated from UI
  3. Reusability

    • ViewModels can be shared across different views
    • Generic services work with multiple data types
    • Modular components for different screens
  4. Maintainability

    • Clear code organization and responsibilities
    • Easy to modify business logic without affecting UI
    • Scalable for future feature additions
  5. SwiftUI Integration

    • Natural fit with SwiftUI's reactive paradigm
    • @Observable provides automatic UI updates
    • Clean data flow from service β†’ ViewModel β†’ View

Key Components

  • Models: Title, TMDBAPIObject, YoutubeSearchResponse
  • ViewModels: ViewModel, SearchViewModel
  • Views: Modular SwiftUI views with reusable components
  • Services: DataFetcher, APIConfig

πŸ”§ Tech Stack

  • Framework: SwiftUI
  • Language: Swift
  • Persistence: SwiftData
  • Networking: URLSession with async/await
  • Architecture: MVVM
  • APIs: TMDB API, YouTube Data API

πŸ“‹ Requirements

  • iOS 17.0+
  • Xcode 15.0+
  • Swift 5.9+

πŸš€ Getting Started

Prerequisites

  1. Valid TMDB API key from The Movie Database
  2. YouTube Data API key from Google Cloud Console

Installation

  1. Clone the repository

    git clone https://github.com/ZifFiji/iOS-Movie-App.git
    cd iOS-Movie-App
  2. Configure API Keys

    cd my-app
    cp APIConfig.json.example APIConfig.json

    Edit APIConfig.json with 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"
    }
  3. Open and Run

    • Open my-app.xcodeproj in Xcode
    • Select your target device or simulator
    • Build and run (⌘+R)

πŸ“± Screenshots

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

🎯 Learning Outcomes

This project demonstrates proficiency in:

SwiftUI Fundamentals

  • Declarative UI development
  • State management with @State, @Environment
  • Navigation with NavigationStack and NavigationPath
  • Custom modifiers and reusable components

iOS Development Patterns

  • MVVM architecture implementation
  • Async/await networking patterns
  • Error handling and user feedback
  • Local data persistence with SwiftData

API Integration

  • RESTful API consumption
  • JSON decoding with Codable
  • Image loading and caching
  • Real-time search implementation

Modern Swift Features

  • Structured concurrency
  • Swift Package Manager integration
  • Type-safe navigation
  • Property wrappers

πŸ™ Acknowledgments

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages