Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Transferable - SwiftUI ドキュメントアプリ

notoroid
December 23, 2022

Transferable - SwiftUI ドキュメントアプリ

札幌iPhoneアプリ開発懇談会勉強会2022年12月向け資料。iOS16 SDKで追加されたTransferableとSwiftUI のドキュメントアプリについての紹介。

notoroid

December 23, 2022
Tweet

More Decks by notoroid

Other Decks in Programming

Transcript

  1. υΩϡϝϯτΞϓϦͷෆຬ఺ w ϑΝΠϧܗࣜͷઃఆ͸NBD04ͱJ1IPOFJ1BEͰ෼͔Ε͍ͯΔ w NBD04༻JOGPQMJTUɺJ1IPOFJ1BE༻JOGPQMJTU w ϑΝΠϧܗࣜʹ͍ͭͯ͸෼͔Εͨ·· ೥ݱࡏ  w

    υΩϡϝϯτΞϓϦΒ͍͠ݟͨ໨ʹͳΒͳ͍ αϙʔτෆ଍  w J04ɺNBD047FOUVSBͰڧԽ w %SBH%SPQରԠ͕ෆे෼ w ೥ʹ5SBOTGFSBCMFΛ࢖ͬͯରԠ
  2. υΩϡϝϯτΞϓϦͷෆຬ఺ w ϑΝΠϧܗࣜͷઃఆ͸NBD04ͱJ1IPOFJ1BEͰ෼͔Ε͍ͯΔ w NBD04༻JOGPQMJTUɺJ1IPOFJ1BE༻JOGPQMJTU w ϑΝΠϧܗࣜʹ͍ͭͯ͸෼͔Εͨ·· ೥ݱࡏ  w

    υΩϡϝϯτΞϓϦΒ͍͠ݟͨ໨ʹͳΒͳ͍ αϙʔτෆ଍  w J04ɺNBD047FOUVSBͰڧԽ w %SBH%SPQରԠ͕ෆे෼ w ೥ʹ5SBOTGFSBCMFΛ࢖ͬͯରԠ /FX
  3. 5SBOTGFSBCMFϓϩτίϧ TUBUJDϝϯόม਺USBOTGFS3FQSFTFOUBUJPOʹରԠ͢Δ @available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0,

    *) public protocol Transferable { /// The type of the representation used to import and export the item. /// /// Swift infers this type from the return value of the /// ``transferRepresentation`` property. associatedtype Representation : TransferRepresentation /// The representation used to import and export the item. /// /// A ``transferRepresentation`` can contain multiple representations /// for different content types. @TransferRepresentationBuilder<Self> static var transferRepresentation: Self.Representation { get } }
  4. 5SBOTGFSBCMFϓϩτίϧ TUBUJDϝϯόม਺USBOTGFS3FQSFTFOUBUJPOʹରԠ͢Δ @available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0,

    *) public protocol Transferable { /// The type of the representation used to import and export the item. /// /// Swift infers this type from the return value of the /// ``transferRepresentation`` property. associatedtype Representation : TransferRepresentation /// The representation used to import and export the item. /// /// A ``transferRepresentation`` can contain multiple representations /// for different content types. @TransferRepresentationBuilder<Self> static var transferRepresentation: Self.Representation { get } } !5SBOTGFS3FQSFTFOUBUJPO#VJMEFS͸ίʔυతͳ ݟͨ໨ͳΫϦʔϯ͞Λҡ࣋ͭͭ͠ɺϏϧυதʹద੾ͳ ίʔυʹมܗ͍ͤͯ͞Δɻ ٕज़తʹ͸4XJGU"UUSJCVUFTΛ࢖༻͠൥ࡶͳίʔυ Λ୹͍ίʔυͱͯ͠දݱՄೳͱ͍ͯ͠Δɻ
  5. 5SBOTGFS3FQSFTFOUBUJPO సૹઌͰ࠶ݱՄೳͳσʔλܗࣜΛࢦఆ͢Δ w %BUB3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞Εͨ%BUBΛ౉͢ w Ұํ޲ͱ૒ํ޲͕Մೳ

    w 'JMF3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞ΕͨϑΝΠϧͷ'JMF63-Λ౉͢ w $PEBCMF3FQSFTFOUBUJPO w $PEBCMFϓϩτίϧʹରԠͨ͠ܗࣜΛ౉͢ w 1SPYZ3FQSFTFOUBUJPO w ,FZ1BUIͰ౉͞ΕͨܗࣜΛ౉͢
  6. 5SBOTGFS3FQSFTFOUBUJPO సૹઌͰ࠶ݱՄೳͳσʔλܗࣜΛࢦఆ͢Δ w %BUB3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞Εͨ%BUBΛ౉͢ w Ұํ޲ͱ૒ํ޲͕Մೳ

    w 'JMF3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞ΕͨϑΝΠϧͷ'JMF63-Λ౉͢ w $PEBCMF3FQSFTFOUBUJPO w $PEBCMFϓϩτίϧʹରԠͨ͠ܗࣜΛ౉͢ w 1SPYZ3FQSFTFOUBUJPO w ,FZ1BUIͰ౉͞ΕͨܗࣜΛ౉͢ έʔεᶄ૒ํ޲ %BUB3FQSFTFOUBUJPO DPOUFOU5ZQF ʜ έʔεᶃҰํ޲ %BUB3FQSFTFOUBUJPO FYQPSUFE$POUF OU5ZQFʜ
  7. 5SBOTGFS3FQSFTFOUBUJPO సૹઌͰ࠶ݱՄೳͳσʔλܗࣜΛࢦఆ͢Δ w %BUB3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞Εͨ%BUBΛ౉͢ w Ұํ޲ͱ૒ํ޲͕Մೳ

    w 'JMF3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞ΕͨϑΝΠϧͷ'JMF63-Λ౉͢ w $PEBCMF3FQSFTFOUBUJPO w $PEBCMFϓϩτίϧʹରԠͨ͠ܗࣜΛ౉͢ w 1SPYZ3FQSFTFOUBUJPO w ,FZ1BUIͰ౉͞ΕͨܗࣜΛ౉͢ έʔεᶃڊେͳϑΝΠϧ FYө૾ϑΝΠϧɺFUD έʔεᶄߏ଄Խ͞ΕͨϑΝΠϧ ϑΝΠϧʹݟ͑Δ͕࣮ࡍ͸ϑΥ ϧμʹؚ·ΕΔෳ਺ͷϑΝΠϧ FYYDPEFͷϓϩδΣΫτϑΝΠ ϧ
  8. 5SBOTGFS3FQSFTFOUBUJPO సૹઌͰ࠶ݱՄೳͳσʔλܗࣜΛࢦఆ͢Δ w %BUB3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞Εͨ%BUBΛ౉͢ w Ұํ޲ͱ૒ํ޲͕Մೳ

    w 'JMF3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞ΕͨϑΝΠϧͷ'JMF63-Λ౉͢ w $PEBCMF3FQSFTFOUBUJPO w $PEBCMFϓϩτίϧʹରԠͨ͠ܗࣜΛ౉͢ w 1SPYZ3FQSFTFOUBUJPO w ,FZ1BUIͰ౉͞ΕͨܗࣜΛ౉͢ 4XJGU6*ͷ*NBHFɺ 4USJOHɺ*OUͳͲ
  9. 5SBOTGFS3FQSFTFOUBUJPO సૹઌͰ࠶ݱՄೳͳσʔλܗࣜΛࢦఆ͢Δ w %BUB3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞Εͨ%BUBΛ౉͢ w Ұํ޲ͱ૒ํ޲͕Մೳ

    w 'JMF3FQSFTFOUBUJPO w 6OJGPSN5ZQF*EFOUJ fi FSTʹొ࿥͞ΕͨϑΝΠϧͷ'JMF63-Λ౉͢ w $PEBCMF3FQSFTFOUBUJPO w $PEBCMFϓϩτίϧʹରԠͨ͠ܗࣜΛ౉͢ w 1SPYZ3FQSFTFOUBUJPO w ,FZ1BUIͰ౉͞ΕͨܗࣜΛ౉͢ 5SBOTGFSBCMFʹରԠͨ͠ ෦෼Λ౉͢͜ͱ͕Ͱ͖Δɻ
  10. 5SBOTGFS3FQSFTFOUBUJPO هड़ྫ struct SymbolDragItem: Transferable { let data: Data let

    image: Image let symbol: Symbol static var transferRepresentation: some TransferRepresentation { DataRepresentation(exportedContentType: .png) { combination in combination.data } ProxyRepresentation(exporting: \.image) ProxyRepresentation(exporting: \.symbol) } }
  11. 5SBOTGFS3FQSFTFOUBUJPO هड़ྫ struct SymbolDragItem: Transferable { let data: Data let

    image: Image let symbol: Symbol static var transferRepresentation: some TransferRepresentation { DataRepresentation(exportedContentType: .png) { combination in combination.data } ProxyRepresentation(exporting: \.image) ProxyRepresentation(exporting: \.symbol) } } όΠφϦσʔλ 1/( 4XJGU6*ͷ*NBHF ಠࣗఆٛ
  12. 4JNQMF4ZNCPM υϥοάΦϒδΣΫτͷੜ੒4JNQMF4ZNCPM%PDVNFOUTXJGU @MainActor func draggableItem() -> SymbolDragItem { return SymbolDragItem(

    data: temporaryData!, image: symbolImage(), symbol: symbol) } @MainActor func symbolImage() -> Image { Image( uiImage: UIImage(data: temporaryData!)! ) }
  13. 4JNQMF4ZNCPM 5SBOTGFSBCMFϓϩτίϧʹରԠͨ͠ߏ଄ମ4JNQMF4ZNCPM%PDVNFOUTXJGU struct SymbolDragItem: Transferable { let data: Data let

    image: Image let symbol: Symbol static var transferRepresentation: some TransferRepresentation { DataRepresentation(exportedContentType: .png) { combination in combination.data } ProxyRepresentation(exporting: \.image) ProxyRepresentation(exporting: \.symbol) } }
  14. 4JNQMF4ZNCPM υϩοϓଆ$POUFOU7JFXTXJGU RoundedRectangle(cornerSize: .init(width: 10, height: 10)) .fill(Color.gray) .overlay {

    dropImage .resizable() .frame(width: proxy.size.height * 0.05, height: proxy.size.height * 0.05) } .frame(width: proxy.size.width * 0.4, height: proxy.size.height * 0.1 ) .dropDestination(for: Image.self) { images, location in dropImage = images.first! return true } ड͚औͬͨ*NBHFΛඳը༻ม਺ʹड͚౉͠
  15. ࢀߟ w 8IBUTOFXJO4XJGU6*88%$7JEFPT"QQMF%FWFMPQFS w IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED w .FFU5SBOTGFSBCMF88%$7JEFPT"QQMF%FWFMPQFS w IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED w

    /PXJO3&"-*5:5FDIJ04ͷ৽ػೳʮ*NBHF3FOEFSFSʯͰ4XJGU6*ͷ7JFXΛ؆୯ʹը૾ʹॻ͖ग़͢ʛ3&"-*5:ʛOPUF w IUUQTOPUFDPNSFBMJUZ@FOHOO w <ϓϨθϯࢿྉ>ϚϧνϓϥοτϑΥʔϜ 4XJGU6* υΩϡϝϯτΞϓϦ w IUUQTJSJNBTVDPNBQQMFNVMUJQMBUGPSNEPDVNFOUBQQTVNNBSZ w <ϓϨθϯࢿྉ> "QQMF͕ ΍Γ͍ͨ์୊4XJGU"UUSJCVUFT w IUUQTJSJNBTVDPNBQQMFTXJGUBUUSJCVUFT