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

Mobile Programming Closure 2

Mobile Programming Closure 2

MobileProgrammingの授業のスライドです

yuichiro_takahashi

October 24, 2018
Tweet

More Decks by yuichiro_takahashi

Other Decks in Technology

Transcript

  1. ςΩετ ࢛ଇԋࢉͷؔ਺ͷྫ func calculate(num1: Int, num2: Int, operator: String) ->

    Int { switch operator { case "+": return num1 + num2 case "-": return num1 - num2 case "*": return num1 + num2 case "/": return num1 / num2 default: return num1 + num2 } } calculate(num1: 10, num2: 20, operator: "ˎ")
  2. ςΩετ ࣮͸৭ʑ໰୊͕ɾɾɾ func calculate(num1: Int, num2: Int, operator: String) ->

    Int { switch operator { case "+": return num1 + num2 case "-": return num1 - num2 case "*": return num1 + num2 case "/": return num1 / num2 default: return num1 + num2 } } calculate(num1: 10, num2: 20, operator: "ˎ") ௕͍switchΛॻ͔ͳ͍ͱ͍͚ͳ͍(ॲཧͷຊ࣭͡Όͳ͍)
  3. ςΩετ ࣮͸৭ʑ໰୊͕ɾɾɾ func calculate(num1: Int, num2: Int, operator: String) ->

    Int { switch operator { case "+": return num1 + num2 case "-": return num1 - num2 case "*": return num1 + num2 case "/": return num1 / num2 default: return num1 + num2 } } calculate(num1: 10, num2: 20, operator: "ˎ") ௕͍switchΛॻ͔ͳ͍ͱ͍͚ͳ͍(ॲཧͷຊ࣭͡Όͳ͍) ਖ਼͍͠จࣈ͕དྷͳ͔ͬͨ࣌΋૝ఆ͠ͳ͍ͱ͍͚ͳ͍(ॲ ཧͷຊ࣭͡Όry)
  4. ςΩετ ࣮͸৭ʑ໰୊͕ɾɾɾ func calculate(num1: Int, num2: Int, operator: String) ->

    Int { switch operator { case "+": return num1 + num2 case "-": return num1 - num2 case "*": return num1 + num2 case "/": return num1 / num2 default: return num1 + num2 } } calculate(num1: 10, num2: 20, operator: "ˎ") ௕͍switchΛॻ͔ͳ͍ͱ͍͚ͳ͍(ॲཧͷຊ࣭͡Όͳ͍) ਖ਼͍͠จࣈ͕དྷͳ͔ͬͨ࣌΋૝ఆ͠ͳ͍ͱ͍͚ͳ͍(ॲ ཧͷຊ࣭͡Όry) ͋ΕΕʙ?͓͔͍ͧ͠ʙ?
  5. ςΩετ ࣮͸৭ʑ໰୊͕ɾɾɾ func calculate(num1: Int, num2: Int, operator: String) ->

    Int { switch operator { case "+": return num1 + num2 case "-": return num1 - num2 case "*": return num1 + num2 case "/": return num1 / num2 default: return num1 + num2 } } calculate(num1: 10, num2: 20, operator: “ˎ”) ௕͍switchΛॻ͔ͳ͍ͱ͍͚ͳ͍(ॲཧͷຊ࣭͡Όͳ͍) ਖ਼͍͠จࣈ͕དྷͳ͔ͬͨ࣌΋૝ఆ͠ͳ͍ͱ͍͚ͳ͍(ॲ ཧͷຊ࣭͡Όry) ͋ΕΕʙ?͓͔͍ͧ͠ʙ? શ֯จࣈ౉ͯ͠ͳ͍ʁ
  6. ςΩετ ࣮͸৭ʑ໰୊͕ɾɾɾ func calculate(num1: Int, num2: Int, operator: String) ->

    Int { switch operator { case "+": return num1 + num2 case "-": return num1 - num2 case "*": return num1 + num2 case "/": return num1 / num2 default: return num1 + num2 } } calculate(num1: 10, num2: 20, operator: “ˎ”) ௕͍switchΛॻ͔ͳ͍ͱ͍͚ͳ͍(ॲཧͷຊ࣭͡Όͳ͍) ਖ਼͍͠จࣈ͕དྷͳ͔ͬͨ࣌΋૝ఆ͠ͳ͍ͱ͍͚ͳ͍(ॲ ཧͷຊ࣭͡Όry) ͋ΕΕʙ?͓͔͍ͧ͠ʙ? શ֯͡Όͳ͍ʁ
  7. ςΩετ ৭ʑͳ໰୊͕ɾɾɾ ▸ ॲཧΛ෼ذͤ͞ΔͨΊʹswitchΛॻ͔ͳ͍ͱ͍͚ͳ͍ ▸ OperatorʹจࣈྻΛ࢖͍ͬͯΔͷͰظ଴͠ͳ͍จࣈ(=ͱ͔)͕͖ͨ৔߹΋૝ఆ͠ͳ͍ ͱ͍͚ͳ͍(default) ▸ operatorͷจࣈྻͱ࣮ࡍͷܭࢉΛ߹Θͤͳ͍ͱ͍͚ͳ͍ ▸

    ԋࢉͷछྨ͕૿͑ͨΒcaseΛ૿΍͞ͳ͍ͱ͍͚ͳ͍ ▸ ؔ਺Λݺͼग़͢ͱ͖ʹ΋operatorͷจࣈΛλΠϙ͠ͳ͍Α͏ʹؾΛ͚ͭͳ͍ͱ͍͚ ͳ͍ ▸ ࢛ଇԋࢉͷؔ਺ͳͷͰܭࢉͤ͞ΔॲཧʹϑΥʔΧε͍͕ͨͦ͠ΕҎ֎ʹॻ͔ͳ͍ͱ ͍͚ͳ͍͜ͱɺߟ͑ͳ͍ͱ͍͚ͳ͍͜ͱ͕ଟ͍
  8. ςΩετ ܭࢉͷॲཧΛҾ਺ͱͯ͠౉ͤͨΒɾɾɾʁ func calculate(num1: Int, num2: Int, calc: (Int, Int)

    -> Int) -> Int { return calc(number1, number2) } // ଍͠ࢉ calculate(num1: 10, num2: 20) { $0 + $1 } // Ҿ͖ࢉ calculate(num1: 10, num2: 20) { $0 - $1 } // ֻ͚ࢉ calculate(num1: 10, num2: 20) { $0 * $1 } // ׂΓࢉ calculate(num1: 10, num2: 20) { $0 / $1 }
  9. ςΩετ ܭࢉͷॲཧΛҾ਺ͱͯ͠౉ͤͨΒɾɾɾʁ func calculate(num1: Int, num2: Int, calc: (Int, Int)

    -> Int) -> Int { return calc(number1, number2) } // ଍͠ࢉ calculate(num1: 10, num2: 20) { $0 + $1 } // Ҿ͖ࢉ calculate(num1: 10, num2: 20) { $0 - $1 } // ֻ͚ࢉ calculate(num1: 10, num2: 20) { $0 * $1 } // ׂΓࢉ calculate(num1: 10, num2: 20) { $0 / $1 } จࣈͷ୅ΘΓʹܭࢉॲཧͦͷ΋ͷΛ౉͢Α͏ʹมߋ(typoͷ ৺഑͕ͳ͘ͳͬͨ)
  10. ςΩετ ܭࢉͷॲཧΛҾ਺ͱͯ͠౉ͤͨΒɾɾɾʁ func calculate(num1: Int, num2: Int, calc: (Int, Int)

    -> Int) -> Int { return calc(number1, number2) } // ଍͠ࢉ calculate(num1: 10, num2: 20) { $0 + $1 } // Ҿ͖ࢉ calculate(num1: 10, num2: 20) { $0 - $1 } // ֻ͚ࢉ calculate(num1: 10, num2: 20) { $0 * $1 } // ׂΓࢉ calculate(num1: 10, num2: 20) { $0 / $1 } switchͷྶѹ͕ɾɾɾফ͑ͨɾɾɾʁ(ॲཧ͕γϯϓ ϧʹ) จࣈͷ୅ΘΓʹܭࢉॲཧͦͷ΋ͷΛ౉͢Α͏ʹมߋ(typoͷ ৺഑͕ͳ͘ͳͬͨ)
  11. ςΩετ ܭࢉͷॲཧΛҾ਺ͱͯ͠౉ͤͨΒɾɾɾʁ func calculate(num1: Int, num2: Int, calc: (Int, Int)

    -> Int) -> Int { return calc(number1, number2) } // ଍͠ࢉ calculate(num1: 10, num2: 20) { $0 + $1 } // Ҿ͖ࢉ calculate(num1: 10, num2: 20) { $0 - $1 } // ֻ͚ࢉ calculate(num1: 10, num2: 20) { $0 * $1 } // ׂΓࢉ calculate(num1: 10, num2: 20) { $0 / $1 } switchͷྶѹ͕ɾɾɾফ͑ͨɾɾɾʁ(ॲཧ͕γϯϓ ϧʹ) จࣈͷ୅ΘΓʹܭࢉॲཧͦͷ΋ͷΛ౉͢Α͏ʹมߋ(typoͷ ৺഑͕ͳ͘ͳͬͨ) ௚઀ॲཧΛ౉͍ͯ͠ΔͷͰߟ ͑Δ͜ͱ͕ݮΔ
  12. ςΩετ ܭࢉͷॲཧΛҾ਺ͱͯ͠౉ͤͨΒɾɾɾʁ func calculate(num1: Int, num2: Int, calc: (Int, Int)

    -> Int) -> Int { return calc(number1, number2) } // ଍͠ࢉ calculate(num1: 10, num2: 20) { $0 + $1 } // Ҿ͖ࢉ calculate(num1: 10, num2: 20) { $0 - $1 } // ֻ͚ࢉ calculate(num1: 10, num2: 20) { $0 * $1 } // ׂΓࢉ calculate(num1: 10, num2: 20) { $0 / $1 } // ༨Γ calculate(num1: 10, num2: 20) { $0 % $1 } switchͷྶѹ͕ɾɾɾফ͑ͨɾɾɾʁ(ॲཧ͕γϯϓ ϧʹ) จࣈͷ୅ΘΓʹܭࢉॲཧͦͷ΋ͷΛ౉͢Α͏ʹมߋ(typoͷ ৺഑͕ͳ͘ͳͬͨ) ௚઀ॲཧΛ౉͍ͯ͠ΔͷͰߟ ͑Δ͜ͱ͕ݮΔ ௚઀ॲཧΛ౉͍ͯ͠Δͷػೳ௥Ճʹ΋Α ΓॊೈͳରԠ͕Մೳʹ
  13. ςΩετ ANDROIDͷϘλϯΛ࣮૷͢Δ৔߹ɾɾɾ public class MainActivity extends AppCompatActivity {
 
 @Override


    protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 findViewById(R.id.button) }
 } ·ͣ͸LayoutϑΝΠϧ͔ΒButtonΛऔಘ
  14. ςΩετ ANDROIDͷϘλϯΛ࣮૷͢Δ৔߹ɾɾɾ public class MainActivity extends AppCompatActivity {
 
 @Override


    protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 findViewById(R.id.button).setOnClickListener(new OnClickListener() {
 
 });
 }
 } OnClickListenerΫϥεΛ࡞੒ͯ͠ɾɾɾ
  15. ςΩετ ANDROIDͷϘλϯΛ࣮૷͢Δ৔߹ɾɾɾ public class MainActivity extends AppCompatActivity {
 
 @Override


    protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 
 }
 });
 }
 } onClickϝιουΛॻ͍ͯɾɾɾ
  16. ςΩετ ANDROIDͷϘλϯΛ࣮૷͢Δ৔߹ɾɾɾ public class MainActivity extends AppCompatActivity {
 
 @Override


    protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 Log.d("Sample", "button is tapped!");
 }
 });
 }
 } λοϓ͞Εͨ࣌ͷίʔυΛॻ͘
  17. ςΩετ ΍͸Γ໰୊͕ɾɾɾ public class MainActivity extends AppCompatActivity {
 
 @Override


    protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 Log.d("Sample", "button is tapped!");
 }
 });
 }
 } λοϓ͞Εͨ࣌ͷॲཧΛॻ͖͍͚ͨͩͳͷʹ࣮૷·Ͱ͕ԕ͍
  18. ςΩετ ΫϩʔδϟΛ௚઀౉ͤΕ͹ɾɾɾ public class MainActivity extends AppCompatActivity {
 
 @Override


    protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 findViewById(R.id.button).setOnClickListener {
 Log.d("Sample", "button is tapped!");
 };
 }
 } ຊ౰ʹॻ͖͍ͨॲཧ͚ͩʹϑΥʔΧεͰ͖Δʂ