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

20211015 Mac CatalystでmacOS用アプリを作る

Kei Ito
October 15, 2021

20211015 Mac CatalystでmacOS用アプリを作る

Kei Ito

October 15, 2021
Tweet

More Decks by Kei Ito

Other Decks in Programming

Transcript

  1. .BD$BUBMZTUͰ
    NBD04༻ΞϓϦΛ࡞Δ
    .PCJMF"DU0/-*/&
    JUPL!ͦΒ͔ͥ

    View full-size slide

  2. JUPL!ͦΒ͔ͥ
    w ͍ͱ͏͚͍ʢJUPLʣ
    w ɹɹɹɹɹɹͷதͷਓ
    w ϞόΠϧΞϓϦΤϯδχΞ݉$&0
    w ෭ۀͰϑϦʔϥϯεత
    w IUUQTJUPLKQ IUUQTTPSBLB[FDPKQ !JUPLKQ

    View full-size slide

  3. ॴࡏ஍ɿژ౎ࢢதژ۠
    ࣾһਓࣗ෼

    View full-size slide

  4. ࣮੷
    डୗ
    ࣗࣾ

    View full-size slide

  5. J04"OESPJENBD048JOEPXTαʔό
    ҰਓͰ΍ͬͯ·͢ʢσβΠϯҎ֎ʣ

    View full-size slide

  6. .BD$BUBMZTUͱ͸

    View full-size slide

  7. J1BEΞϓϦΛNBD04্Ͱಈ͔͢࢓૊Έ
    6*,JUΛNBD04্Ͱಈ͔͢࢓૊Έ

    View full-size slide

  8. 6*,JU
    "QQ,JU
    NBD04
    J04
    J1BE04
    XBUDI04
    UW04
    6*ͷϑϨʔϜϫʔΫ͸ผ෺

    View full-size slide

  9. J1BEΞϓϦΛNBD04Ͱಈ͔͢
    w "QQMF4JMJDPO੡.BDݶఆ
    ‎ Ұ෦ͷϢʔβͷΈɺJ1BEΞϓϦͱ·ͬͨ͘ಉ͡
    w 4XJGU6*Ͱڞ௨Խ
    ‎ ৽ن࡞੒ʢPSϑϧεΫϥονʣ
    w .BD$BUBMZTU
    ‎ طଘͷϦιʔεΛ༗ޮ׆༻ʁ

    View full-size slide

  10. J04J1BE04ΞϓϦ

    View full-size slide

  11. NBD04Ͱಈ͔͢
    ։ൃத

    View full-size slide

  12. .BD$BUBMZTUͷߏ଄

    View full-size slide

  13. $BUBMZTUͷߏ଄
    "QQ,JU
    NBD04
    6*,JU
    ஫ɿΠϝʔδ
    ࣮૷ͱͯ͠͸6*,JUଆ͕ϝΠϯ
    "QQ,JUͷΨϫΛ͔Ϳͬͯಈ͍͍ͯΔ

    View full-size slide

  14. Ϋϥεؒͷؔ܎
    "QQ,JU
    NBD04
    6*,JU
    6*7JFX$POUSPMMFS
    /48JOEPX
    /4"QQMJDBUJPO
    6*"QQMJDBUJPO
    6*4DFOF
    6*8JOEPX

    View full-size slide

  15. Ϋϥεؒͷؔ܎
    "QQ,JU
    NBD04
    6*,JU
    6*7JFX$POUSPMMFS
    /48JOEPX
    /4"QQMJDBUJPO
    6*"QQMJDBUJPO
    6*4DFOF
    6*8JOEPX ͓͕͍ͨͷ͜ͱ͸
    ؔ஌͍ͯ͠ͳ͍

    View full-size slide

  16. ࣮ࡍʹ΍ͬͯΈΔ

    View full-size slide

  17. .VMUJQMFXJOEPXT
    8JOEPXΛด͡ΔͱΞϓϦ͸ऴྃ͢Δ
    ऴྃͤͨ͘͞ͳ͍৔߹͸NVMUJQMFXJOEPXTʹରԠ͢Δ
    ˠ6*4DFOF6*4DFOF%FMFHBUF

    View full-size slide

  18. .VMUJQMFXJOEPXT
    ։ൃத

    View full-size slide

  19. 6*ύʔπ
    6*4XJUDIUJUMF #JH4VSҎ߱

    View full-size slide

  20. 6*ύʔπ
    button.menu = UIMenu(title: "", options: .displayInline, children: [


    UIAction(title: "item1", handler: { _ in }),


    UIAction(title: "item2", handler: { _ in }),


    UIAction(title: "item3", handler: { _ in }),


    UIAction(title: "item4", handler: { _ in })


    ])


    button.showsMenuAsPrimaryAction = true


    View full-size slide


  21. IUUQTEFWFMPQFSBQQMFDPNEFTJHOIVNBOJOUFSGBDFHVJEFMJOFT
    NBDDBUBMZTUPWFSWJFXWJTVBMEFTJHO
    J1BE04 NBD04

    View full-size slide

  22. "QQ,JU͞ΘΓ͍ͨ

    View full-size slide

  23. "QQ,JUͷԸܙ

    View full-size slide

  24. #VOEMFܦ༝Ͱ
    "QQ,JUʹΞΫηε
    "QQ,JU
    NBD04
    6*,JU
    6*7JFX$POUSPMMFS
    /48JOEPX
    /4"QQMJDBUJPO
    6*"QQMJDBUJPO
    6*4DFOF
    6*8JOEPX
    #VOEMF

    View full-size slide

  25. #VOEMFͷߏ੒
    "QQ,JU
    NBD04
    6*,JU
    7JFX$POUSPMMFS
    #VOEMF
    "QQ,JU1MVHJO
    1MVHJOQSPUPDPM

    View full-size slide

  26. #VOEMF࡞੒

    View full-size slide

  27. 1MVHJOTXJGU
    import Foundation


    @objc(Plugin)


    protocol Plugin: NSObjectProtocol {


    init()


    func doSomethingWithAppKit()


    }
    6*,JUଆʹݟͤΔQSPUPDPMΛఆٛ

    View full-size slide

  28. "QQ1MVHJOTXJGU
    import AppKit


    class AppKitPlugin: NSObject, Plugin {


    required override init() {


    }


    func doSomethingWithAppKit() {


    let bar = NSStatusBar.system


    statusItem = bar.statusItem(withLength: 100)


    statusItem?.button?.title = "..."


    }


    }
    "QQ,JUΛ࢖࣮ͬͨ૷

    View full-size slide

  29. *OGPQMJTU
    NSPrincipalClass


    AppKitPlugin
    Ϋϥε໊ΛӅ΃͍
    ʢ6*,JUଆ͔Β۩৅ΫϥεΛ஌Δඞཁ͕ͳ͘ͳΔʣ

    View full-size slide

  30. 7JFX$POUSPMMFSTXJGU
    import UIKit


    class ViewController: UIViewController {


    func loadPlugin() {


    let bundleFileName = "AppKitPlugin.bundle"


    guard let bundleURL =


    Bundle.main.builtInPlugInsURL?.appendingPathComponent(bundleFileName),


    let bundle = Bundle(url: bundleURL) else {


    return


    }


    guard let pluginClass = bundle.principalClass as? Plugin.Type else {


    return


    }


    let plugin = pluginClass.init()


    plugin.doSomethingWithAppKit()


    }


    }

    View full-size slide

  31. ·ͱΊ
    w .BD$BUBMZTU
    w NBD04༻ΞϓϦΛ࡞Δબ୒ࢶͷҰͭͱͯ͠
    w طଘϦιʔεΛ׆༻ͭͭ͠
    ɹɹɹɹɹɹɹɹNBD04Ͱ΋ಉ͡ϢʔβମݧΛ
    w 8JEHFUΛ޿͘࢖ͬͯ΋Β͏ͨΊʹ͸ศར͔΋
    w J1BEΞϓϦͷҠ২Λݕ౼ͯ͠Έͯ͸ʁ

    View full-size slide