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

How to read Swift

How to read Swift

声に出して読みたいSwift

Yusuke Hosonuma

February 14, 2015
Tweet

More Decks by Yusuke Hosonuma

Other Decks in Programming

Transcript

  1. ຊ౰ʹʁ var name: String? var name: String! var name: String

    = userName ?? "Guest" func sum(number1 a:Int, number2 b:Int) -> Int { return a + b } fruits.sort({ (s1: String, s2: String) -> Bool in return s1 < s2 }) func say(greet: String) -> (String -> String) { func greet(name: String) -> String { return "\(greet), \(name)!" } return greet }
  2. Lesson4: ͜͏ಡΈ·͢ var name: String = userName ?? "Guest" ᶃม਺nameʹ

    ᶄuserNameʹ஋͕ೖͬͯͨΒ ᶅͦͷத਎ ᶆೖͬͯͳ͚Ε͹͜Ε ᶇΛ୅ೖ͢Δ
  3. Lesson5: ͜͏ಡΈ·͢ func sayHello(name s:String) -> String { return “Hello,

    \(s)!” } sayHello(name: "Yusuke") ᶃϝιου ᶅStringܕͰఆٛ͞Εͨ ᶄsayHello͸ ᶆsͱ͍͏Ҿ਺Λड͚औΓ ᶇStringܕͷ݁ՌΛฦ͢ ᶈͪͳΈʹݺͼग़͢ͱ͖ʹ͸ nameͰࢦఆͯ͠΋Β͏
  4. Lesson6: ͜͏ಡΈ·͢ fruits.sort({ (s1: String, s2: String) -> Bool in

    return s1 < s2 }) ᶃsortʹ༩͑ΔΫϩʔδϟ{}͸ ᶄStringܕͷ(s1, s2)ΛҾ਺ʹड͚औΓ ᶅBoolܕΛฦ͢ ᶆͦͯ͠ ᶇ࣮ࡍͷॲཧ͸͜͏ͳΔ
  5. ॓୊: ؔ਺Λฦؔ͢਺ func say(greet: String) -> (String -> String) {

    func greet(name: String) -> String { return "\(greet), \(name)!" } return greet } let sayHello = say("Hello") sayHello(name: "Hosonuma") sayHello(name: "Yusuke")