Slide 1

Slide 1 text

Swift String Interpolation USAMI Kosuke Fenrir Inc.

Slide 2

Slide 2 text

String Interpolation let price = 2 let number = 3 let message = "One cookie: $\(price), \(number) cookies:" + "$\(price * number)."

Slide 3

Slide 3 text

จࣈྻิؒ͸खܰͰศརͰ͢Ͷ » ͚ͩͲɺϩδοΫ෦෼Ͱ͸࢖Θͳ͍ํ͕͍͍ » URL ͱ͔ΫΤϦͱ͔Ͱ͸ආ͚Δ » ݁Ռ͕༧ଌͮ͠Β͍ͨΊ » ͋͘·Ͱɺ͓खܰදࣔ༻ͷػೳͰ͋Δ

Slide 4

Slide 4 text

จࣈྻิ͕ؒͲͷΑ͏ʹߦΘΕΔ͔ » ExpressibleByStringInterpolation ϓϩτίϧʹઆ໌͕͋Δ » ·ͣɺϦςϥϧ෦෼ͱิؒ෦෼ʹ෼ׂ͞ΕΔ » ͦΕͧΕͷิؒ෦෼͕ init(stringInterpolationSegment:) ʹ౉ ͞ΕΔ » ͦΕΒͷ݁Ռ͕ init(stringInterpolation:) ʹ౉͞ΕΔ

Slide 5

Slide 5 text

͜Μͳײ͡ let message = String(stringInterpolation: String(stringInterpolationSegment: "One cookie: $"), String(stringInterpolationSegment: price), String(stringInterpolationSegment: ", "), String(stringInterpolationSegment: number), String(stringInterpolationSegment: " cookies: $"), String(stringInterpolationSegment: price * number), String(stringInterpolationSegment: "."))

Slide 6

Slide 6 text

ExpressibleByStringInterpolation » ͭ·Γɺ͜ͷϓϩτίϧΛࣗલͰ࣮૷͢Ε͹ΧελϚΠζͰ͖Δ » ͔࣮͠͠͸ɺ͜ΕΛ࣮૷͢Δඞཁ͸͋·Γͳ͍ʢޙड़ʣ

Slide 7

Slide 7 text

จࣈྻิؒͷσϑΥϧτͷৼΔ෣͍ » String.init(describing:) Λฦ͢Α͏࣮૷͞Ε͍ͯΔ » ͨͩ͠ɺ͍͔ͭ͘ͷϏϧτΠϯܕ͸ผ࣮૷ʢBool ͳͲʣ » ref : https://github.com/apple/swift/blob/swift-3.0.1- RELEASE/stdlib/public/core/StringInterpolation.swift.gyb

Slide 8

Slide 8 text

String.init(describing:) » TextOutputStreamable ʹద߹͍ͯͨ͠Β .write(to: s) Λฦ͢ » CustomStringConvertible ʹద߹͍ͯͨ͠Β .description Λฦ͢ » CustomDebugStringConvertible ʹద߹͍ͯͨ͠ Β .debugDescription Λฦ͢ » ͦΕҎ֎͸ Swift ඪ४ϥΠϒϥϦ͕ࣗಈੜ੒͢Δ

Slide 9

Slide 9 text

ࣗલclassΛจࣈྻิؒʹରԠ͢Δʹ͸ » ExpressibleByStringInterpolation ͡Όͳͯ͘΋͍͍ » ྫ͑͹ CustomStringConvertible ͷ .description Λ࣮૷ » ͩ͜ΘΒͳ͍ͳΒɺඪ४·͔ͤͰ΋ग़ྗ͸͞ΕΔ

Slide 10

Slide 10 text

ͱ͜ΖͰ Swift 4 Ͱ͸ɾɾɾ » ExpressibleByStringInterpolation ͸ deprecated » SwiftDoc.org » Deprecated: it will be replaced or redesigned in Swift 4.0. Instead of conforming to 'ExpressibleByStringInterpolation', consider adding an 'init(_:String)'.

Slide 11

Slide 11 text

Ͳ͏ͳΔͷʁ » Proposal SE-0137 : Avoiding Lock-In to Legacy Protocol Designs » We know this protocol to be mis-designed and limited, but there's no time to fix it for Swift 3. » ࠶ઃܭ͞ΕΔ༧ఆΒ͍͠ » Ϧςϥϧ෦෼ͱิؒ෦෼ʹ෼ׂɺͱ͔ buggy ͳײ͡

Slide 12

Slide 12 text

ࢀߟ » SwiftDoc.org » github.com/apple/swift » Swift ͷ Bool ͷจࣈྻදݱͷݴޠ࢓༷ - ja.stackoverflow.com