Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UTI

 UTI

Presented at potatotips 19

cockscomb

July 14, 2015
Tweet

More Decks by cockscomb

Other Decks in Programming

Transcript

  1. gion-matsuri.jpg

    View full-size slide

  2. ion-matsuri.jpg

    View full-size slide

  3. JPEG
    image/jpeg
    .jpeg public.jpeg

    View full-size slide

  4. PNG
    image/png
    .png public.png

    View full-size slide

  5. PNG
    image/png
    .png public.png
    Extension MIME Type UTI

    View full-size slide

  6. File Types

    have many representations
    • Extension — .jpeg
    • MIME Type — image/jpeg
    • UTI — public.jpeg

    View full-size slide

  7. File Types

    have many representations
    • Extension
    • for file name
    • MIME Type
    • for Internet (Content-Type)
    • UTI?

    View full-size slide

  8. Uniform Type Identifier

    View full-size slide

  9. Uniform Type Identifier
    • Used inside iOS/OS X
    • Have inheritance
    • public.content/public.data → public.image
    → public.jpeg

    View full-size slide

  10. let manager = PHImageManager.defaultManager()
    manager.requestImageDataForAsset(asset,
    options: options) {
    (data, dataUTI, orientation, info) in
    // Do something
    }
    Get image data from Photos

    View full-size slide

  11. let manager = PHImageManager.defaultManager()
    manager.requestImageDataForAsset(asset,
    options: options) {
    (data, dataUTI, orientation, info) in
    // Do something
    }
    Get image data from Photos

    View full-size slide

  12. UTI → Extension
    UTTypeCopyPreferredTagWithClass(
    "public.jpeg",
    kUTTagClassFilenameExtension
    ).takeRetainedValue()
    // jpeg

    View full-size slide

  13. MIME Type → UTI
    UTTypeCreatePreferredIdentifierForTag(
    kUTTagClassMIMEType,
    "image/jpeg",
    nil
    ).takeRetainedValue()
    // public.jpeg

    View full-size slide

  14. MIME Type → Extension
    func extensionFromMIMEType(MIMEType: String) -> String
    {
    let uti = UTTypeCreatePreferredIdentifierForTag(
    kUTTagClassMIMEType,
    MIMEType,
    nil
    ).takeRetainedValue()
    let ext = UTTypeCopyPreferredTagWithClass(
    uti,
    kUTTagClassFilenameExtension
    ).takeRetainedValue()
    return ext as String
    }
    extensionFromMIMEType("image/jpeg")

    View full-size slide

  15. cockscomb/UTIKit

    View full-size slide

  16. MIME Type → Extension
    func extensionFromMIMEType(MIMEType: String) -> String
    {
    let uti = UTTypeCreatePreferredIdentifierForTag(
    kUTTagClassMIMEType,
    MIMEType,
    nil
    ).takeRetainedValue()
    let ext = UTTypeCopyPreferredTagWithClass(
    uti,
    kUTTagClassFilenameExtension
    ).takeRetainedValue()
    return ext as String
    }
    extensionFromMIMEType("image/jpeg")

    View full-size slide

  17. MIME Type → Extension
    import UTIKit
    UTI(MIMEType: "image/jpeg").filenameExtension

    View full-size slide

  18. Create your file type


    CFBundleTypeIconFiles

    CFBundleTypeName
    Awesome File Format
    LSItemContentTypes

    info.cockscomb.awesome



    View full-size slide

  19. Uniform Type Identifier
    • Can convert to file extension and MIME Type
    • Can be simple to use with UTIKit ✌
    • Can be defined your own one

    View full-size slide






  20. http://hatenacorp.jp/recruit/

    View full-size slide