Reputation: 591
In my code below, I am using NSBundle. According to the documentation (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/#//apple_ref/occ/clm/NSBundle/bundleWithURL:), you need to import Foundation to use NSBundle.
However, in my code below, I don't import Foundation but I am able to use NSBundle. Why is this?
I thought it might be because I import AVFoundation and AVFoundation inherits from NSObject; however, when I read the documentation, AVFoundation isn't listed as being inherited from NSObject.
import UIKit
import AVFoundation
class PlaySoundsViewController: UIViewController {
var audioPlayer:AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if var filePath = NSBundle.mainBundle().pathForResource("movie_quote", ofType: "mp3") {
var filePathUrl = NSURL.fileURLWithPath(filePath)
audioPlayer = AVAudioPlayer(contentsOfURL: filePathUrl, error: nil)
}else {
println("the file path is empty")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func playSlowAudio(sender: UIButton) {
audioPlayer.play()
}
}
Upvotes: 0
Views: 1347
Reputation: 9825
UIKit
imports Foundation
and you inherit anything the things you import publicly import.
Upvotes: 2