: 실행 가능한 코드와 자원을 포함하고 있는 디렉토리 (info.plist, assets etc…)

❖ [Main Bundle]

let mainBundle = Bundle.main

// 이미지에 접근
if let imageURL = mainBundle.url(forResource: "photo", withExtension: "jpg") {
	...
}

// 위치
mainBundle.bundleURL

// 식별자
mainbundle.bundleIdentifier

❖ 사용 예시

  1. 이미지 로드
if let imageURL = Bundle.main.url(forResource: "avatar", withExtension: "png"),
   let imageData = try? **Data(contentsOf**: imageURL) {
    let image = UIImage(data: imageData)
}
  1. 소리 로드
if let soundURL = Bundle.main.url(forResource: "click", withExtension: "mp3") {
    let soundPlayer = try? AVAudioPlayer(contentsOf: soundURL)
    soundPlayer?.play()
}
  1. json파일 로드
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)
}
  1. 국제화
let localizedString = NSLocalizedString("Hello", tableName: nil, bundle: Bundle.main, value: "", content: "")
  1. 스토리보드 로드
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let viewController = storyboard.instantiateViewController(withIdentifier: "MyViewController")