0

Let's say I has a audio player app and there is song list (tableView) in VC1 to present all the songs and clicking any row of it to open another VC2 to present the playing scene. In this playing scene there is some buttons for playing sequence (repeat, repeatOne, shuffle).

Since user will frequently dismissed/popup this VC2 to get back to VC1 (song list), I store the playing sequence button value to another file called SongData.swift and define a static var static var repeatOneSequence = false to store the value of VC2. Then retrieve it if SongData.repeatOneSequence == true like this in VC2.

Now it is working, but it is just my way...I didn't get info about how to do it properly. I'm wondering if there is other way to store the data of dismissed VC2 or which way is the better one to do it.

/ / / Insert code snip for reference

    @IBAction func repeatButton(_ sender: UIButton) {
        if SongData.repeatOneSequence == true {
            print("repeatOneSequence TRUE!")
            repeatButton.setImage(UIImage(named: "icons8-repeat-50"), for: .normal)
            repeatButton.imageView?.contentMode = .scaleAspectFit
            SongData.repeatOneSequence = false
        } else {
            print("repeatOneSequence FALSE!")
            repeatButton.setImage(UIImage(named: "icons8-repeat-one-50"), for: .normal)
            repeatButton.imageView?.contentMode = .scaleAspectFit
            SongData.repeatOneSequence = true
        }
    }
2
  • See stackoverflow.com/questions/5210535/…. Be sure to look at several of the answers, not just the first. Commented Oct 8, 2019 at 3:35
  • rmaddy, thanks, it is a long thread but really worth to read, well per my current knowledge of Swift, I couldn't understand all of it, but some points and approaches is helpful to me, could know that many way to transfer data in Swift. It seems that send value back to VC1 when dismiss VC2(use protocol and delegate) could be preferred way, but a bit complicate code. And my current way is to save data of VC2 into my Model class. Commented Oct 8, 2019 at 4:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.