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

String Interpolation

Avatar for USAMI Kosuke USAMI Kosuke
November 28, 2016

String Interpolation

Avatar for USAMI Kosuke

USAMI Kosuke

November 28, 2016
Tweet

More Decks by USAMI Kosuke

Other Decks in Programming

Transcript

  1. String Interpolation let price = 2 let number = 3

    let message = "One cookie: $\(price), \(number) cookies:" + "$\(price * number)."
  2. ͜Μͳײ͡ 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: "."))
  3. จࣈྻิؒͷσϑΥϧτͷৼΔ෣͍ » String.init(describing:) Λฦ͢Α͏࣮૷͞Ε͍ͯΔ » ͨͩ͠ɺ͍͔ͭ͘ͷϏϧτΠϯܕ͸ผ࣮૷ʢBool ͳͲʣ » ref :

    https://github.com/apple/swift/blob/swift-3.0.1- RELEASE/stdlib/public/core/StringInterpolation.swift.gyb
  4. String.init(describing:) » TextOutputStreamable ʹద߹͍ͯͨ͠Β .write(to: s) Λฦ͢ » CustomStringConvertible ʹద߹͍ͯͨ͠Β

    .description Λฦ͢ » CustomDebugStringConvertible ʹద߹͍ͯͨ͠ Β .debugDescription Λฦ͢ » ͦΕҎ֎͸ Swift ඪ४ϥΠϒϥϦ͕ࣗಈੜ੒͢Δ
  5. ͱ͜ΖͰ 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)'.
  6. Ͳ͏ͳΔͷʁ » 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 ͳײ͡