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

SwiftのWebAssembly対応の軌跡 / The State of Swift Web...

Yuta Saito
September 21, 2020

SwiftのWebAssembly対応の軌跡 / The State of Swift WebAssembly

Yuta Saito

September 21, 2020
Tweet

More Decks by Yuta Saito

Other Decks in Programming

Transcript

  1. swiftwasm/JavaScriptKit JavaScriptͱͷόΠϯσΟϯάϥΠϒϥϦ • JavaScript likeͳΦϒδΣ Ϋτૢ࡞APIΛఏڙ • JavaScriptͱSwiftͷGCͷ ࠩΛҰ෦ٵऩ import

    JavaScriptKit let alert = JSObject.global.alert.function! let document = JSObject.global.document.object! let div = document.createElement!("div").object! div.innerText = "Hello, world" let body = document.body.object! body.appendChild!(div) alert("Swift is running on browser!") 18
  2. TokamakUI/Tokamak SwiftUIޓ׵ͷUIϥΠϒϥϦ • ΫϩεϓϥοτϑΥʔϜΛ લఏʹઃܭ • WebAssembly/DOMɺ Static HTMLΛαϙʔτ import

    TokamakDOM struct Counter: View { @State var count: Int = 0 var body: some View { VStack { Text("\(count)") HStack { Button("Reset") { count = 0 } Button("Increment") { count += 1 } } } } } 20
  3. όΠφϦαΠζ໰୊ (ICU) • Swift͸Unicodeσʔλϕʔ ε΍ਖ਼نԽͷͨΊʹICUʹ ґଘ͍ͯ͠Δ • ICU͚ͩͰ4MBҎ্ let emoji:

    UnicodeScalar = " " emoji.properties.isEmoji // true // Pokémon let str1 = "Poke\u{0301}mon" // Pokémon let str2 = "Pok\u{00e9}mon" str1 == str2 // true ICU = International Components for Unicode 23
  4. ৽͍͠όΠφϦαΠζ࠷దԽ ϞδϡʔϧΛލ͍Ͱ࢖ΘΕͳ͍ίʔυΛ࡟আ͢Δ͜ͱͰόΠφ ϦαΠζΛ࡟ݮ // LibX.swift public protocol P { func

    foo() func unusedMethod() } public struct S: P { public func foo() {} public func unusedMethod() {} } // main.swift import LibX func useP<T: P>(_ value: T) { value.foo() } useP(S()) 26
  5. ৽͍͠όΠφϦαΠζ࠷దԽ ϞδϡʔϧΛލ͍Ͱ࢖ΘΕͳ͍ίʔυΛ࡟আ͢Δ͜ͱͰόΠφ ϦαΠζΛ࡟ݮ // LibX.swift public protocol P { func

    foo() func unusedMethod() } public struct S: P { public func foo() {} public func unusedMethod() {} } // main.swift import LibX func useP<T: P>(_ value: T) { value.foo() } useP(S()) 26