您好,在此先感謝您的幫助。我正在採取一個快速的udemy課程,我已經完成了5次代碼,並將其與教練進行了比較,就我所知,它是相同的。我無法弄清楚爲什麼我的代碼無法正常工作。它說「類」ViewController「沒有初始化器」,我該如何解決這個問題? https://gyazo.com/1c9d0f5d8de70991aff353ac66505ab8swift中的多個錯誤,類未初始化,無法調用非函數類型的值'Bundle'
1 // ViewController.swift
2 // RetroCalculator
3 //
4 // Created by miles richie on 2/22/17.
5 // Copyright © 2017 Mit3ch. All rights reserved.
6 //
7
8 import UIKit
9 import AVFoundation
10
11 class ViewController: UIViewController {
12
13 var btnSound: AVAudioPlayer
14
15 override func viewDidLoad() {
16 super.viewDidLoad()
17
18 let path = Bundle.main.path(forResource: "btn", ofType: "wav")
19 let soundURL = URL(fileURLWithPath: path!)
20
21 do{
22 try btnSound = AVAudioPlayer(contentsOf: soundURL)
23 btnSound.prepareToPlay()
24 } catch let err as NSError{
25 print(err.debugDescription)
26 }
27 }
28
29 @IBAction func numberPressed(sender: UIButton) {
30
31 }
32
33 func playSound(){
34 if btnSound.isPlaying{
35 btnSound.stop()
36 }
37}
38}
請[編輯]你的問題並將相關代碼粘貼到您的問題中。清楚地指出哪些線路導致問題幷包含完整的錯誤消息。 – rmaddy