UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Using the LaunchScreen in a SwiftUI app

Forums > SwiftUI

Hi, I just wrote a SwiftUI app that reads in the Media Library at the start of the app. This is a somewhat lengthy task and hence I wanted to display a progress bar on the LaunchScreen. I found the necessary elements and put a Progress Bar object into the launch screen View Controller but I don't seem to be able to update it with actual progress.

One thing I noticed is that the circle is empty at the beginning of the line of where I define the @IBOutlet but this is how it is created on control drag from my LauchScreen into the code.

Here is my code:

import UIKit import MediaPlayer import SwiftUI import Foundation

class Library { var artists : [Artist] = [] @IBOutlet var progressBar: UIProgressView! @EnvironmentObject var settings : UserSettings var counter : Float = 0 var total : Float = 0

init() {
    let filter : Set<MPMediaPropertyPredicate> = [MPMediaPropertyPredicate(value: MPMediaType.music.rawValue, forProperty: MPMediaItemPropertyMediaType)]
    let mediaQuery = MPMediaQuery(filterPredicates: filter )
    var artistsInCollection : [Artist] = []

    progressBar = UIProgressView(progressViewStyle: .default)

    total = Float(mediaQuery.items?.count ?? 0)

    for item in mediaQuery.items! {

        // there is some code here which is irrelevant to my question.

        counter += 1
        print(counter)
        progressBar.setProgress(counter/total, animated: true)
     }
     self.artists = artistsInCollection

}

}

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.