【Xcode/Swift】音を鳴らす方法

//
//  ViewController.swift
//  temporary
//
//  Created by RikutoSato on 2021/06/07.
//

import UIKit
import AVFoundation

class ViewController: UIViewController {
    
    var player:AVAudioPlayer?
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    @IBAction func buttonAction(_ sender: Any) {
        let soundURL = Bundle.main.url(forResource: "sound", withExtension: "mp3")
        do {
            player = try AVAudioPlayer(contentsOf: soundURL!)
            player?.play()
        } catch {
            print("error...")
        }
    }
}