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
}
}