Slide 1

Slide 1 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. USFBTUSBJO5BOBLB3ZPHB 1 potatotips #81 
 iOS / Android ։ൃ Tips ڞ༗ձ #potatotips ଘࡏܕʹʮBOZʯΛ෇͚͍ͯͳ͍ͱ͖ʹ 
 ίϯύΠϧΤϥʔʹ͢Δ 4&1JFDFNFBMBEPQUJPOPGVQDPNJOHMBOHVBHF JNQSPWFNFOUTͷ࢖༻ྫ

Slide 2

Slide 2 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. "CPVUNF USFBTUSBJO5BOBLB3ZPHB 2 4XJGU J04 XBUDI04 $PSF/'$ 044 
 ɹɹJU`TNZNPUIFSUPOHVF 
 ɹɹ࠷ۙ.JTTLFZJPΛ͸͡Ί·ͨ͠ 
 ɹɹɹɹ.BTUPEPOͳͲͱ΋ܨ͕ΕΔ'FEJWFSTFͰ͢ ɹɹɹɹɹɹɹɹɹɹ!USFBTUSBJOɹɹIUUQTUSFUKQ 
 
 %F/"$P -UE 
 ɹɹJ04"QQ%FWFMPQFSʢ"QSJM$VSSFOUʣ

Slide 3

Slide 3 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. ௚લͰൃද಺༰Λมߋ͠·ͨ͠ ʮΫϩʔδϟΛ༻͍ͨඇಉظύλʔϯΛ"TZOD4USFBNʹม͑ͯΈͨʯͷ༧ఆͰͨ͠ 3 QPUBUPUJQTuQPUBUPUJQTQPUBUPUJQT8JLJIUUQTHJUIVCDPNQPUBUPUJQTQPUBUPUJQTXJLJQPUBUPUJQT

Slide 4

Slide 4 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. ௚લͰൃද಺༰Λมߋ͠·ͨ͠ ʮΫϩʔδϟΛ༻͍ͨඇಉظύλʔϯΛ"TZOD4USFBNʹม͑ͯΈͨʯͷ༧ఆͰͨ͠ 4 9DPEFCFUB &G ࠷৽χϡʔε"QQMF%FWFMPQFSIUUQTEFWFMPQFSBQQMFDPNKQOFXTSFMFBTFT JEG

Slide 5

Slide 5 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. ଘࡏܕ &YJTUFOUJBM5ZQFT 5 protocol Fruit {} struct Apple: Fruit {} struct Banana: Fruit {} func fruit1() -> Fruit { Apple() } var fruit2: Fruit = fruit1() fruit2 = Banana() // ✅

Slide 6

Slide 6 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. 0QBRVFܕ 0QBRVF5ZQFTʢ4XJGUɺ4XJGUʣ 6 protocol Fruit {} struct Apple: Fruit {} struct Banana: Fruit {} // Swift 5.1+ func fruit3() -> some Fruit { Apple() } // Swift 5.7+ var fruit4: some Fruit = fruit3() fruit4 = Banana() // ❌ Cannot assign value of type 'Banana' to type 'some Fruit'

Slide 7

Slide 7 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. ଘࡏܕ &YJTUFOUJBM5ZQFTʢ4XJGUʣ 7 protocol Fruit {} struct Apple: Fruit {} struct Banana: Fruit {} // Swift 5.6+ func fruit5() -> any Fruit { Apple() } // Swift 5.6+ var fruit6: any Fruit = fruit5() fruit6 = Banana() // ✅

Slide 8

Slide 8 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. ଘࡏܕ &YJTUFOUJBM5ZQFTʢ4XJGUΑΓ΋લ·Ͱʣ 8 protocol Fruit {} func fruit1() -> Fruit { /* ... */ } var fruit2: Fruit = fruit1() protocol Fruit {} func fruit5() -> any Fruit { /* ... */ } var fruit6: any Fruit = fruit5()

Slide 9

Slide 9 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. ଘࡏܕ &YJTUFOUJBM5ZQFTʢ4XJGUҎ߱Ͱ͸ʣ 9 protocol Fruit {} func fruit1() -> Fruit { /* ... */ } var fruit2: Fruit = fruit1() protocol Fruit {} func fruit5() -> any Fruit { /* ... */ } var fruit6: any Fruit = fruit5()

Slide 10

Slide 10 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. ʮ4XJGUҎ߱Ͱ͸ʜʜʯ 4XJGUͰ͸ഁյతมߋ͕ଟ͘ݟࠐ·ΕΔ w 4XJGUܥͷϓϩδΣΫτ͔Β4XJGUܥʹҠߦ͢Δʹ͸ରԠ͕ඞཁ w Ͱ͖Ε͹ࠓͷ͏͔ͪΒ4XJGU޲͚ͷରԠΛ͓͖͍ͯͨ͠ w ʮBOZΛ෇͚͍ͯͳ͍ଘࡏܕʯͷ͢΂ͯΛͲ͏΍ͬͯ୳͢ʜʜʁ w ʮ4XJGUҎ߱Ͱ͸ʜʜʯͳͲͷػೳͷҰ෦Λɺ 
 ໌ࣔతʹ༗ޮʹ͓͖͍ͯͨ͠ w ίϯύΠϧΤϥʔɾܯࠂͳͲͰ༰қʹؾ͚ͮΔΑ͏ʹͳΔ 10

Slide 11

Slide 11 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. 11 1JFDFNFBMBEPQUJPOPGVQDPNJOH MBOHVBHFJNQSPWFNFOUT 4&ɹকདྷ௥Ճ༧ఆͷݴޠվળ΁ͷஈ֊తͳద༻ ೔ຊޠ༁͸IUUQTHJUIVCDPNTU[O4XJGU1PEDBTUCMPCNBJOESBGUT4XJGUকདྷ௥Ճ༧ఆͷݴޠվળ΁ͷஈ֊తͳద༻NEΑΓ

Slide 12

Slide 12 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. কདྷ௥Ճ༧ఆͷݴޠվળ΁ͷஈ֊తͳద༻ 4XJGU w 4XJGUίϯύΠϥʹ௥Ճ͞Εͨ 
 -enable-upcoming-feature XϑϥάΛ༻͍Δ w Xʹ͸ద༻͍ͤͨ͞কདྷ௥Ճ༧ఆͷݴޠվળͷػೳͷ໊લΛࢦఆ͢Δ w &YJTUFOUJBM"OZ w 4USJDU$PODVSSFODZ w #BSF4MBTI3FHFY-JUFSBMTɹFUD 12 IUUQTHJUIVCDPNBQQMFTXJGUFWPMVUJPOCMPCNBJOQSPQPTBMTQJFDFNFBMGVUVSFGFBUVSFTNE

Slide 13

Slide 13 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. -enable-upcoming-feature ExistentialAny 4XJGU͔ͭ4XJGUΑΓ΋લ·Ͱ 13 protocol Fruit {} func fruit1() -> Fruit { /* ... */ } var fruit2: Fruit = fruit1() protocol Fruit {} func fruit5() -> any Fruit { /* ... */ } var fruit6: any Fruit = fruit5() 6TFPGQSPUPDPM'SVJUBTBUZQF NVTUCFXSJUUFOBOZ'SVJU

Slide 14

Slide 14 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. কདྷ௥Ճ༧ఆͷݴޠվળ΁ͷஈ֊తͳద༻ ࢖༻ྫ w 4XJGU1BDLBHFͷλʔήοτʹద༻͢Δ w 9DPEFϓϩδΣΫτͷλʔήοτʹద༻͢Δ 14

Slide 15

Slide 15 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. 4XJGU1BDLBHFͷλʔήοτʹద༻͢Δ কདྷ௥Ճ༧ఆͷݴޠվળ΁ͷஈ֊తͳద༻ 15 // PackageDescription 5.8+ public struct SwiftSetting: Encodable { // ... @available(_PackageDescription, introduced: 5.8) public static func enableUpcomingFeature( _ name: String, _ condition: BuildSettingCondition? = nil ) -> SwiftSetting // ... }

Slide 16

Slide 16 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. 4XJGU1BDLBHFͷλʔήοτʹద༻͢Δ কདྷ௥Ճ༧ఆͷݴޠվળ΁ͷஈ֊తͳద༻ 16 // swift-tools-version: 5.8 import PackageDescription let package = Package( name: "MyPackage", // ... targets: [ .target( name: "MyTarget", swiftSettings: [ .enableUpcomingFeature("ExistentialAny", .when(configuration: .debug)), ] ), ] // ... )

Slide 17

Slide 17 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. 9DPEFϓϩδΣΫτͷλʔήοτʹద༻͢Δ কདྷ௥Ճ༧ఆͷݴޠվળ΁ͷஈ֊తͳద༻ 17 9DPEFͷεΫϦʔϯγϣοτʢ-enable-upcoming-featureΛ࢖͏ʹ͸4XJGUʢ9DPEFʣҎ͕߱ඞཁ͕ͩɺݱ࣌఺ͰCFUB൛ͷͨΊ୅༻ʣ

Slide 18

Slide 18 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. 9DPEFϓϩδΣΫτͷλʔήοτʹద༻͢Δ কདྷ௥Ճ༧ఆͷݴޠվળ΁ͷஈ֊తͳద༻ 18 9DPEFͷεΫϦʔϯγϣοτʢ-enable-upcoming-featureΛ࢖͏ʹ͸4XJGUʢ9DPEFʣҎ͕߱ඞཁ͕ͩɺݱ࣌఺ͰCFUB൛ͷͨΊ୅༻ʣ

Slide 19

Slide 19 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. 9DPEF͕ఏҊͨ͠௨ΓʹҰؾʹमਖ਼͢Δ ͓·͚ w ϝχϡʔͷ 
 ʮ&EJUPSʯʮ'JY"MM*TTVFTʯͰ Ұؾʹमਖ਼ఏҊΛ൓өͰ͖Δ w ࠓճͷ&YJTUFOUJBM"OZͷྫͰ͸ɺ 9DPEFͷఏҊ͕ 
 ޡ͍ͬͯΔ৔߹͕͋Δ 
 ʢ࠶౓ίϯύΠϧΤϥʔʹͳΔʣ 19 9DPEFͷεΫϦʔϯγϣοτ

Slide 20

Slide 20 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. ·ͱΊ ଘࡏܕʹʮBOZʯΛ෇͚͍ͯͳ͍ͱ͖ʹίϯύΠϧΤϥʔʹ͢Δ w 4XJGU͔Βʮকདྷ௥Ճ༧ఆͷݴޠվળ΁ͷஈ֊తͳద༻ʯΛߦ͏ͨΊͷ ίϯύΠϥϑϥάʢ-enable-upcoming-feature XʣͳͲ͕௥Ճ͞ΕΔ w 4XJGU1BDLBHFͷλʔήοτ SwiftSetting.enableUpcomingFeature(_:_:) Ͱnameʹ"ExistentialAny"Λࢦఆ͢Δ w 9DPEFϓϩδΣΫτͷλʔήοτ 
 ʮ4XJGU$PNQJMFS$VTUPN'MBHTʯʮ0UIFS4XJGU'MBHT ʢOTHER_SWIFT_FLAGSʣʯʹ 
 -enable-upcoming-feature ExistentialAnyΛ௥Ճ͢Δ 20

Slide 21

Slide 21 text

Copyright © 2023 treastrain / Tanaka RyogaɹAll rights reserved. ɹɹɹɹɹεϥΠυɾൃද಺༰͸IUUQTUSFUKQͰެ։͍ͯ͠·͢ɹ⏩ 21 ଘࡏܕʹʮBOZʯΛ෇͚͍ͯͳ͍ͱ͖ʹ 
 ίϯύΠϧΤϥʔʹ͢Δ 4&1JFDFNFBMBEPQUJPOPGVQDPNJOHMBOHVBHF JNQSPWFNFOUTͷ࢖༻ྫ potatotips #81 
 iOS / Android ։ൃ Tips ڞ༗ձ #potatotips