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

Mobile Programming Constants

Mobile Programming Constants

Mobile Programming 授業のスライドです

yuichiro_takahashi

October 01, 2018
Tweet

More Decks by yuichiro_takahashi

Other Decks in Technology

Transcript

  1. ม਺(VARIABLE)ͱ͸ ▸ ࣮ࡍͷίʔυ // ม਺ఆٛ var num: Int = 20

    var name: String = "HAG" // ܕΛলུ͢Δ͜ͱ΋Մೳ var number = 10 // ఆٛࡁΈͷม਺ʹޙ͔Β஋ΛೖΕΒΕΔ num = 45 number = 29 // ͜Ε͸ܕ͕ҧ͏͔Βμϝ(ErrorʹͳΔ·͢) name = 45 // ͜Ε͸஋ೖͬͯͳ͍͔Βμϝ(ErrorʹͳΔ·͢) var number: Int // nil΋ೖΕ͓ͯ͘͜ͱ͸Ͱ͖ͳ͍ʢErrorʹͳΔ·͢)
 var number: Int = nil // ม਺Λར༻͢Δ print("number is: \(number)")
  2. ఆ਺(VALUE)ͱ͸ ▸ ม਺ͱಉ͘͡จࣈ΍੔਺ͳͲϓϩάϥϜதͰѻ͏σʔλΛೖΕΔϞϊ(ͱݴ ͏ΑΓ஋ʹϥϕϧΛషΔΑ͏ͳ΋ͷʁ) ▸ Ұ౓ఆٛͨ͠ఆ਺ʹޙ͔Βผͷ஋ΛೖΕΔ͜ͱ͸Ͱ͖ͳ͍ɻ ▸ ఆ਺ʹ஋ΛೖΕΔ͜ͱΛ”ଋറ(bind)”ͱݺͿɻ ▸ Swift

    Ͱ͸ “let” ͱ͍͏Ωʔϫʔυ͔Β࢝·Δ ▸ ӳޠͷ਺ֶͷදݱͷ let x be 3 (xΛ3ͱ͢Δ)͔Β͖͍ͯΔΒ͍͠ ▸ ఆ਺ʹ͸ఆٛͨ͠ܕ͔͠ೖΕΒΕͳ͍ ▸ ม਺͸ఆٛͨ࣌͠ʹඞͣॳظԽ͞Ε͍ͯΔඞཁ͕͋Δ <- NEW!
  3. ఆ਺(VALUE)ͱ͸ ▸ ࣮ࡍͷίʔυ // ఆ਺ఆٛ let name: String = “THE

    SHAPE" let double: Double = 114.514 // ܕΛলུ͢Δ͜ͱ΋Ͱ͖Δ let age = 25 // ఆٛࡁΈͷఆ਺ʹޙ͔Β஋ΛೖΕΔ͜ͱ͸Ͱ͖ͳ͍(͜Ε͸ΤϥʔʹͳΔ·͢) name = “Onii-chan” // ఆٛͨ͠ܕͱಉ͡஋͔͠ೖΕΒΕͳ͍(͜Ε΋ΤϥʔʹͳΔ·͢) let number: Int = "are you ok?" let string: String = 2020 // ͜Ε͸஋ೖͬͯͳ͍͔Βμϝ(ErrorʹͳΔ·͢) let number: Int // nil΋ೖΕ͓ͯ͘͜ͱ͸Ͱ͖ͳ͍ʢErrorʹͳΔ·͢)
 let number: Int = nil // ఆ਺Λར༻͢Δ print(“your age is... \(100000 + age)”) print("Oh! you are !")
  4. ·ͱΊΔͱ ‣ SwiftͰ͸ “var”, ఆ਺͸ “let”Ͱఆٛ͢Δ ▸ Ұ౓ఆٛͨ͠ม਺͸ޙ͔Β஋ΛೖΕΒΕΔɻఆ਺͸ޙ͔Β ஋ΛೖΕΒΕͳ͍ ▸

    ม਺ʹ஋ΛೖΕΔͷ͸୅ೖ, ఆ਺ʹ஋ΛೖΕΔͷ͸ଋറͱݺ Ϳ ▸ ม਺ʹ΋ఆ਺ʹ΋ఆٛͨ͠ܕ͔͠ೖΕΒΕͳ͍
  5. είʔϓʁ ▸ είʔϓͱ͸ม਺ͷ༗ޮൣғͷ͜ͱ ▸ SwiftͳͲͷଟ͘ͷݴޠͰ͸if ΍ϝιουͳͲͷ {} Ͱείʔϓ͕۠ ੾ΒΕΔ(ϒϩοΫείʔϓ) ▸

    είʔϓͷ಺ଆ͔Β֎ଆͷม਺ΛݟΔ͜ͱ͕Ͱ͖Δ͕֎ଆ͔Β಺ ଆͷม਺ΛݟΔ͜ͱ͸Ͱ͖ͳ͍ ▸ είʔϓ͔Β֎Εͨม਺͸ࣗಈతʹղ์͞ΕΔ ▸ ؔ਺͝ͱʹείʔϓ͕੾ΒΕΔมଶݴޠ΋͋Δ(functionείʔϓ) ▸ ओʹϩʔΧϧείʔϓͱάϩʔόϧείʔϓͰ෼͚ΒΕΔ
  6. ϩʔΧϧείʔϓ func someFunction() { let a = “hoge" print(a) //

    OK } print(a) // ίϯύΠϧΤϥʔ someFunction() ▸ ؔ਺΍Ϋϥεɺ੍ޚߏจ(ifͱ͔)ͷதͳͲ͘͝ڱ͍ൣғͰఆٛ͞ΕΔείʔϓ ▸ ؔ਺΍ΫϥεɺifͳͲͷϒϩοΫ಺ͰͷΈ༗ޮ ▸ ม਺͕ݟ͑Δൣғ͕ڱ͍ͷͰҙਤ͠ͳ͍มߋ͕ى͜Γʹ͍͘
  7. ࢀরܕͱ஋ܕ ▸ લड़ͷ෼ྨҎ֎ʹ΋Swiftʹ͸ೋͭͷ෼ྨ͕͋Δ ▸ ClassͰఆٛ͞Ε͍ͯΔ΋ͷ͸ ‘ࢀরܕ’, Struct Ͱఆٛ͞Εͯ ͍Δ΋ͷ͸ ‘஋ܕ’ͱݺ͹ΕΔ

    ▸ ྫ͑͹ Int ΍ String ͳͲ͸஋ܕ , UIImageͳͲͷΫϥε͸ࢀ রܕ ▸ ࢀরܕ͸஋ͷ͋Δ৔ॴΛɺ஋ܕ͸஋ͦͷ΋ͷΛม਺ʹ࣋ͬͯ ͍Δ
  8. ςΩετ FLOATING TYPE(ුಈখ਺఺) ▸ গ਺ҎԼΛද͢Ϋϥε ▸ Float, Double, CGFloat ▸

    CGFloat͸CPUͷੑೳʹΑͬͯDouble, FloatΛ੾Γସ͑Δ ▸ ਺ࣈͷܭࢉ͕͘͢͝ΊΜͲ͍͘͞ ▸ ҟͳΔܕͷ҉໧తܕม׵͸ແ͠
  9. ςΩετ BOOL TYPE(࿦ཧܕ) ▸ ਖ਼͔ෛ͔Λද͢Ϋϥε ▸ ओʹifจͰ࢖͍·͢ ▸ true or

    false ▸ IntܕΛ୅ΘΓʹ࢖͏͜ͱ͸Ͱ͖ͳ͍ ▸ ࡾ߲ԋࢉࢠΛαϙʔτͯ͠·͢ ▸ ௕͍ॲཧ͸ࡾ߲ԋࢉࢠʹ͸ॻ͔ͳ͍
  10. ςΩετ COLLECTION TYPE (഑ྻ, ࣙॻܕ) ▸ Swiftʹ΋഑ྻ͸͋Δ ▸ Arrayͱݺͼ·͢ ▸

    Arrayʹ͸ಉ͡ܕ͔͠ೖΕΒΕͳ͍ ▸ Array<Int>ΑΓ΋[Int]Λ࢖͏ ▸
  11. ςΩετ COLLECTION TYPE (഑ྻ, ࣙॻܕ) ▸ Swiftʹ΋ࣙॻܕ͕͋Δ ▸ Dictionaryͱݺͼ·͢ ▸

    Dictionaryʹ΋ಉ͡ܕ͔͠ೖΕΒΕͳ͍ ▸ Dictionary<String: Int>ΑΓ΋[String: Int]Λ࢖͏ ▸ ॱ൪͸อো͞Εͳ͍
  12. ςΩετ ܕม׵ʁ ▸ ͋Δܕ͔Βผͷܕʹม׵͢Δ͜ͱΛܕม׵ͱ͍͏ ▸ String͔ΒIntʹม׵͢ΔͳͲ͕ܕม׵ʹ౰ͨΔ ▸ String͔ΒIntʹม׵͚ͨ͠Ε͹ String(10) ͱ͍͏ܗʹͳΔ

    ▸ ܕม׵͸ඞͣ੒ޭ͢Δͱ͸ݶΒͳ͍૊Έ߹Θͤ΋͋ΔͷͰ optional(nil͔΋͠Εͳ͍ܕ)͕ฦΔ ▸ as? as! as Λ࢖༻ͨ͠μ΢ϯΩϟετͱݺ͹ΕΔํ๏΋ଘࡏ͢Δ