A representation of the code and resources stored in a bundle directory on disk.
디스크의 번들 디렉터리에 저장된 코드 및 리소스의 표현입니다.
Apple은 번들을 사용하여 애플리케이션, 프레임워크, 플러그인 및 기타 많은 특정 콘텐츠 유형을 나타냅니다. 번들은 포함된 리소스를 잘 정의된 하위 디렉토리로 구성하고 번들 구조는 플랫폼과 번들 유형에 따라 다릅니다. 번들 개체를 사용하면 번들의 구조를 몰라도 번들의 리소스에 액세스할 수 있습니다. 번들 개체는 번들 구조, 사용자 기본 설정, 사용 가능한 지역화 및 기타 관련 요소를 고려하여 항목을 찾을 수 있는 단일 인터페이스를 제공합니다.
Any executable can use a bundle object to locate resources, either inside an app’s bundle or in a known bundle located elsewhere. You don't use a bundle object to locate files in a container directory or in other parts of the file system.
모든 실행 파일은 번들 개체를 사용하여 앱 번들 내부 또는 다른 위치에 있는 알려진 번들에서 리소스를 찾을 수 있습니다. 컨테이너 디렉토리나 파일 시스템의 다른 부분에서 번들 개체를 사용하여 파일을 찾지 않습니다.
번들 개체를 사용하는 일반적인 패턴은 다음과 같습니다.
Before you can locate a resource, you must first specify which bundle contains it. The Bundle class has many constructors, but the one you use most often is main. The main bundle represents the bundle directory that contains the currently executing code. So for an app, the main bundle object gives you access to the resources that shipped with your app.
리소스를 찾으려면 먼저 리소스를 포함하는 번들을 지정해야 합니다. 번들 클래스에는 많은 생성자가 있지만 가장 자주 사용하는 생성자는 기본입니다. 기본 번들은 현재 실행 중인 코드가 포함된 번들 디렉토리를 나타냅니다. 따라서 앱의 경우 기본 번들 개체를 통해 앱과 함께 제공된 리소스에 액세스할 수 있습니다.
앱이 플러그인, 프레임워크 또는 기타 번들 컨텐츠와 직접 상호 작용하는 경우 이 클래스의 다른 방법을 사용하여 적절한 번들 개체를 생성할 수 있습니다. 항상 알려진 URL이나 경로에서 번들 개체를 생성할 수 있지만 다른 방법을 사용하면 앱에서 이미 사용 중인 번들에 더 쉽게 액세스할 수 있습니다. 예를 들어 프레임워크에 연결하는 경우 init(for:) 방법을 사용하여 해당 프레임워크에 정의된 클래스를 기반으로 프레임워크 번들을 찾을 수 있습니다.
// Get the app's main bundle
let mainBundle = Bundle.main
// Get the bundle containing the specified private class.
let myBundle = Bundle(for: NSClassFromString("MyPrivateClass")!)
Returns the file URL for the resource identified by the specified name and file extension.
지정된 이름 및 파일 확장명으로 식별된 리소스의 파일 URL을 반환합니다.
func url(forResource name: String?,
withExtension ext: String?) -> URL?
name
The name of the resource file.
리소스 파일의 이름
If you specify nil, the method returns the first resource file it finds with the specified extension.
nil을 설정할경우, 지정된 확장명으로 찾은 첫번째 리소스 파일이 호출됩니다.
extension
The extension of the resource file.
리소스 파일의 확장명
If extension is an empty string or nil, the extension is assumed not to exist and the file URL is the first file encountered that exactly matches name.
확장명이 nil과 같은 경우는 존재하지 않으며, 파일 URL은 이름과 정확히 일치하는 첫 번째 파일입니다.
The file URL for the resource file or nil if the file could not be located.
리소스 파일의 URL을 반환하거나, 파일을 찾을 수 없는 경우엔 nil을 반환한다.