Bundle

Tabber·2021년 7월 5일
0

Apple Document

목록 보기
3/12

A representation of the code and resources stored in a bundle directory on disk.
디스크의 번들 디렉터리에 저장된 코드 및 리소스의 표현입니다.

Overview


Apple uses bundles to represent apps, frameworks, plug-ins, and many other specific types of content. Bundles organize their contained resources into well-defined subdirectories, and bundle structures vary depending on the platform and the type of the bundle. By using a bundle object, you can access a bundle's resources without knowing the structure of the bundle. The bundle object provides a single interface for locating items, taking into account the bundle structure, user preferences, available localizations, and other relevant factors.

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.

모든 실행 파일은 번들 개체를 사용하여 앱 번들 내부 또는 다른 위치에 있는 알려진 번들에서 리소스를 찾을 수 있습니다. 컨테이너 디렉토리나 파일 시스템의 다른 부분에서 번들 개체를 사용하여 파일을 찾지 않습니다.


The general pattern for using a bundle object is as follows:

번들 개체를 사용하는 일반적인 패턴은 다음과 같습니다.

  • Create a bundle object for the intended bundle directory.
    원하는 번들 디렉토리에 대한 번들 개체를 생성합니다.
  • Use the methods of the bundle object to locate or load the needed resource.
    번들 개체의 메서드를 사용하여 필요한 리소스를 찾거나 로드합니다.
  • Use other system APIs to interact with the resource.
    다른 시스템 API를 사용하여 리소스와 상호 작용합니다.

Finding and Opening a Bundle

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.

리소스를 찾으려면 먼저 리소스를 포함하는 번들을 지정해야 합니다. 번들 클래스에는 많은 생성자가 있지만 가장 자주 사용하는 생성자는 기본입니다. 기본 번들은 현재 실행 중인 코드가 포함된 번들 디렉토리를 나타냅니다. 따라서 앱의 경우 기본 번들 개체를 통해 앱과 함께 제공된 리소스에 액세스할 수 있습니다.


If your app interacts directly with plug-ins, frameworks, or other bundled content, you can use other methods of this class to create appropriate bundle objects. You can always create bundle objects from a known URL or path, but other methods make it easier to access bundles your app is already using. For example, if you link to a framework, you can use the init(for:) method to locate the framework bundle based on a class defined in that framework.

앱이 플러그인, 프레임워크 또는 기타 번들 컨텐츠와 직접 상호 작용하는 경우 이 클래스의 다른 방법을 사용하여 적절한 번들 개체를 생성할 수 있습니다. 항상 알려진 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")!)

Bundle.main.url(forResource:withExtension:)

Returns the file URL for the resource identified by the specified name and file extension.
지정된 이름 및 파일 확장명으로 식별된 리소스의 파일 URL을 반환합니다.

Declaration

func url(forResource name: String?, 
withExtension ext: String?) -> URL?

Parameters

  • 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은 이름과 정확히 일치하는 첫 번째 파일입니다.

Return Value

The file URL for the resource file or nil if the file could not be located.
리소스 파일의 URL을 반환하거나, 파일을 찾을 수 없는 경우엔 nil을 반환한다.

profile
iOS 정복중인 Tabber 입니다.

0개의 댓글