: 실행 가능한 코드와 자원을 포함하고 있는 디렉토리 (info.plist, assets etc…)
❖ [Main Bundle]
let mainBundle = Bundle.main
// 이미지에 접근
if let imageURL = mainBundle.url(forResource: "photo", withExtension: "jpg") {
...
}
// 위치
mainBundle.bundleURL
// 식별자
mainbundle.bundleIdentifier
❖ 사용 예시
if let imageURL = Bundle.main.url(forResource: "avatar", withExtension: "png"),
let imageData = try? **Data(contentsOf**: imageURL) {
let image = UIImage(data: imageData)
}
if let soundURL = Bundle.main.url(forResource: "click", withExtension: "mp3") {
let soundPlayer = try? AVAudioPlayer(contentsOf: soundURL)
soundPlayer?.play()
}
if let jsonURL = Bundle.main.url(forResource: "config", withExtension: "json"),
let data = try? Data(contentsOf: jsonURL) {
let config = try? JSONDecoder().decode(Configuration.self, from: data)
}
let localizedString = NSLocalizedString("Hello", tableName: nil, bundle: Bundle.main, value: "", content: "")
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let viewController = storyboard.instantiateViewController(withIdentifier: "MyViewController")