Giter VIP home page Giter VIP logo

itunesfeedswiftui's Introduction

ITunesFeedSwiftUI

Alt text

This library provides SwiftUI Views and ObservableObject for fetching iTunes Feed using ITunesFeedGenerator library

Features

  • Displays song/book/app in a List/Grid using MediaListItemView.
  • Displays song/book/app in an embedded webview using MediaDetailView.
  • Provides Observable Objects to fetch song/book/app.

Installation

A detailed guide for installation can be found in Installation Guide. Make sure you use iOS 16, macOS 13 Ventura as target deployment for your app.

Swift Package Manager

Example

Displays 25 Most Played Songs Feed from Singapore in a List

struct SongsFeed: View {
    
    @StateObject var vm = SongListObservableObject(region: "sg", resultLimit: .limit25)
    
    var body: some View {
        List(vm.results ?? []) { 
            MediaListItemView(song: $0)
        }.overlay(overlayView)
            .navigationTitle("Most Played Songs (SG)")
            .task {
                if vm.results == nil {
                    vm.fetchMedia()
                }
            }
    }
}

Displays 50 Top Paid Books Feed from US in a List

struct BooksFeed: View {
    
    @StateObject var vm = BookListObservableObject(region: "sg", resultLimit: .limit50, pricingType: .paid)
    
    var body: some View {
        List(vm.results ?? []) { 
            MediaListItemView(book: $0)
        }.overlay(overlayView)
            .navigationTitle("Top Paid Books (US)")
            .task {
                if vm.results == nil {
                    vm.fetchMedia()
                }
            }
    }
}

Displays 50 Top Free Apps Feed from US in a List

struct BooksFeed: View {
    
    @StateObject var vm = AppListObservableObject(region: "sg", resultLimit: .limit50, pricingType: .free)
    
    var body: some View {
        List(vm.results ?? []) { 
            MediaListItemView(app: $0)
        }.overlay(overlayView)
            .navigationTitle("Top Free Apps (US)")
            .task {
                if vm.results == nil {
                    vm.fetchMedia()
                }
            }
    }
}

Handle Loading/Failure/Empty cases

You can access the phase enum. It contains 3 cases each for success, failure, and loading. The example below declare an overlayView that can be passed to overlay modifier in View.

@ViewBuilder
private var overlayView: some View {
    switch songsVM.phase {
    case .success(let feed) where feed.results.isEmpty:
        Text("Feed is empty")
    case .failure(let error):
        Text(error.localizedDescription)
    case .loading:
        ProgressView()
    default: EmptyView()
    }
}

Displays song iTunes detail web Page in WKWebView

MediaDetailView(song: song)

Supported Region Code Strings

You can get the list of all supported region code parameters from this GitHub Gist. Kudos to Marcus Stöhr/daFish

itunesfeedswiftui's People

Contributors

alfianlosari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.