简体   繁体   中英

Referring to an audio file in Bundle, Xcode sees 'Use of unresolved identifier issue'

After reading through the (many) questions about 'use of unresolved' identifier issues ( example ), the answer typically seems to be adding a class and then ensuring it is targeted using File Inspector.

I am not trying to create a new class -- I am trying to target an MP3 file that is in the Bundle using AVAudioPlayer :

//5 -
var songPlayer = AVAudioPlayer()

//6 -
func prepareSongAndSession() {

    do {
        //7 - Insert the song from our Bundle into our AVAudioPlayer
        songPlayer = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "03 Smile", ofType: "mp3")!))

Xcode flags the final line with: Unresolved identifier 'Bundle' . I don't understand why, as I understood the Bundle acts as a directory.

Finally, I thought maybe the MP3 did not copy itself into the directory when I dragged the file. After going to the root file > Build Phases, I have confirmed the file is listed in "Copy Bundle Resources."

Am I missing something?

Xcode 7.3 & Swift 2.2.

Current Apple documentation is for Swift 4. Simply update Xcode to latest stable version and you'll be able to code according to documentation, without this error of undefined reference to Bundle .

Also note that Xcode 9 will be mandatory at some point of July 2018 to publish on iTunes Connect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM