來源:蘋果官方文檔
引入
蘋果建議過去 pasteboard 類型的形式不應該再用了武学,要盡可能使用 UTIs祭往。
Pboard 類型會在未來的發(fā)布里被棄用。在 macOS 10.6 和以后應該替換所有 pboard 類型的使用未 UTIs火窒,包括在Types for Standard Data (macOS 10.6 and later)中介紹的常量硼补。
概述
Uniform Type Identifiers(即 UTIs)是唯一標識抽象類型的字符串。它們可以被用來描述文件格式或內(nèi)存中的數(shù)據(jù)類型熏矿,但也可以被用來描述其它種類實體的類型已骇,比如目錄、用量或包票编。
類型聲明出現(xiàn)在二進制 property list褪储,告訴系統(tǒng)關于一個類型的一些事情。關于格式的詳細信息以及UTI的聲明可以在 Uniform Type Identifiers Overview里找到慧域。
聲明中包括的幾個關鍵概念:
- 一致性鲤竹。一致性關系在類型之間建立了多個繼承體系。類型 property 值在運行時可能被繼承昔榴,根據(jù)每個類型的一致性關系宛裕。如果一個類型的聲明不包括特定類型 property 的值,然后類型的超類型會被用來搜尋值论泛。超類型被深度優(yōu)先搜索揩尸,順序就是類型聲明中給定的順序。這是唯一的方式屁奏,所以聲明的超類型順序是很重要的岩榆。
- 標簽。標簽是指明類型的定義的字符串,用一些其他類型的認定算法勇边,比如文件名擴展或MIME類型犹撒。其他類型認定算法的命名空間被稱作它的類。uniform type identifiers 通過類識別它們自己粒褒,所以有效的標簽類設置在未來可以被輕易擴展识颊。
- 類型聲明也可能包含幾個其它 property:類型的本地化用戶描述,二進制聲明里圖標資源的名字奕坟,參考 URL 指明關于類型本身的技術文檔祥款,以及一個版本號,類型升級的時候可以遞增月杉。這些 property 全部都是可選的刃跛。
特征
創(chuàng)建 uniform type identifiers
func UTTypeCreatePreferredIdentifierForTag(CFString, CFString, CFString?)
為創(chuàng)建特定標簽指明的類型創(chuàng)建uniform type identifier。
func UTTypeCreateAllIdentifiersForTag(CFString, CFString, CFString?)
創(chuàng)建由特定標簽指明的類型的 uniform type identifiers 數(shù)組苛萎。
從 uniform type identifiers 獲得標簽
用一個不同的類型分類方法翻譯一個 uniform type identifier 為一列標簽桨昙。
測試 uniform type identifiers
func UTTypeEqual(CFString, CFString)
返回兩個 uniform type identifiers 是否相等。
func UTTypeConformsTo(CFString, CFString)
返回一個 uniform type identifier 是否符合另一個 uniform type identifier腌歉。
獲得額外類型信息
func UTTypeCopyDescription(CFString)
返回uniform type identifier相關的本地化的蛙酪、用戶可讀的類型描述字符串。
func UTTypeCopyDeclaration(CFString)
返回一個 uniform type 的聲明翘盖。
func UTTypeCopyDeclaringBundleURL(CFString)
返回類型包含聲明的二進制文件位置桂塞。
OSType Conversion Utilities
func UTCreateStringForOSType(OSType)
Encodes an OSType into a string suitable for use as a tag argument.
func UTGetOSTypeFromString(CFString)
Decodes a tag string into an OSType.
常量
Type Declaration Dictionary Keys
These are keys for values found in a UTI dictionary. For more information about UTI dictionaries, see [Uniform Type Identifiers Overview](Uniform Type Identifiers Overview).
Type Tag Classes
These strings identify other tagging classification schemes that a uniform type identifier can be converted to and from.
UTI Abstract Types
These are abstract uniform type identifiers that most other type identifiers are derived from.
UTI Concrete Types
These are uniform type identifiers for concrete types.
UTI Text Types
These are the uniform type identifiers for text content.
UTI Composite Content Types
Uniform type identifiers for content that includes multiple data types.
UTI Image Content Types
Uniform type identifiers for graphics content.
UTI Audio Visual Content Types
Uniform type identifier for audio and video content.
UTI Directory Types
Uniform type identifiers for different directory types.
UTI Application Types
Uniform type identifiers for application types.
UTI Contact Types
Uniform type identifiers for contact types.
UTI Miscellaneous Types
Uniform type identifiers for types that do not fit in other categories.