New to swift and the view controller paradigm. Would like to know if ViewControllers automatically come with the objects it describes for example, does avplayerviewcontroller automatically come with an avplayer object ready to be used or do we still need to create an avplayer object? Another example could be uitableviewcontroller, does it automatically come with a tableview object or do we need to create it after creating a cocoa touch class that subclasses uitableviewcontroller.
Here is some example code that compiles where I didn't necessarily create an avplayer object but it seems like that object was already ready to be used through a property called 'player':
import UIKit
import AVKit
import AVFoundation
class MeetTheAuthorViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//playBackgroundMusic("bensound-jazzyfrenchy-castlesbackground.mp3")
// Do any additional setup after loading the view.
}
func btn_clicked(_ sender: UIBarButtonItem) {
// Do something
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "videoSegue"
{
//set up the player
let videoURL = Bundle.main.url(forResource: "The Atlanta Goat_ Part One-HD", withExtension: "mp4")
let videoViewController = segue.destination as! AVPlayerViewController
videoViewController.player = AVPlayer(url: videoURL!)
videoViewController.player?.play()
}
}
}