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

Mobile Programming Function

Mobile Programming Function

MobileProgramming の授業のスライドです

yuichiro_takahashi

October 22, 2018
Tweet

More Decks by yuichiro_takahashi

Other Decks in Technology

Transcript

  1. ؔ਺෼ΫοΩϯά func add(number1: Int, number2: Int) { } w ࣍ʹؔ਺͕ड͚औΔ஋Ҿ਺Λઃఆ͍͖ͯ͠·͢

    w ࠓճ͸଍͠ࢉͷؔ਺ͳͷͰҾ਺͸ೋͭʹͳΓ·͢ w Ҿ਺͸໊લܕͱ͍͏ܗͰఆٛ͞Ε w ෳ਺͋Δ৔߹͸ΧϯϚͰ۠੾Γ·͢ Ҿ਺ Ҿ਺ Ҿ਺ಉ࢜͸ΧϯϚͰ۠੾Δ
  2. ؔ਺෼ΫοΩϯά func add(number1: Int, number2: Int) -> Int { }

    w ࣍ʹ໭Γ஋ΛܾΊ·͢ w ໭Γ஋͸ؔ਺͕ͲΜͳ஋Λฦ͢ͷ͔Λࣔ͢΋ͷͰ͢ w ໭Γ஋͸جຊతʹҰͭͰ͕͢5VQMFΛ࢖͏͜ͱͰෳ਺ݸฦͤ·͢ w ྫ͑͹ࠓճ͸଍͠ࢉͷؔ਺ͳͷͰ*OUܕΛҰͭฦ͠·͢ w Կ΋ฦ͢΋ͷ͕ͳ͍৔߹͸লུՄೳͰ͢ w ͪͳΈʹฦΓ஋ͱ΋ݴͬͨΓ͠·͕͢৭ʑΞϨͳͷͰࠓճ͸໭Γ஋ͱݺͼ·͢ ͜ͷ෦෼͕໭Γ஋
  3. ؔ਺෼ΫοΩϯά func add(number1: Int, number2: Int) -> Int { let

    result = number1 + number2 return result } w ࠷ޙʹؔ਺ͷத਎Λهड़͍͖ͯ͠·͢ w ໭Γ஋͕͋Δؔ਺ͷ৔߹͸ඞͣ࠷ޙʹ w SFUVSOΛ࢖༻ͯ͠஋Λฦ͢ඞཁ͕͋Γ·͢ ໭Γ஋Λฦ͢ ؔ਺Ͱߦ͏ॲཧ
  4. ؔ਺ͷݺͼग़͠ w ఆٛͨؔ͠਺͸ݺͼग़͞ΕΔ·Ͱ͸࣮ߦ͞Εͳ͍ w ͦͷͨΊఆٛͨ͠ޙʹඞͣݺͼग़͢ඞཁ͕͋Δ // ؔ਺ఆٛ func add(number1: Int,

    number2: Int) -> Int { let result = number1 + number2 return result } // ؔ਺ͷݺͼग़͠ let added = add(number1: 10, number2: 10) print("result is: \(added)") // 20
  5. ֎෦Ҿ਺໊ w ֎෦Ҿ਺໊͸Ҿ਺໊ͱ͸ผʹΘ͔Γ΍͍͢ϥϕϧΛ͚ͭ ΒΕΔػೳͷ͜ͱ w ֎෦Ҿ਺໊͸ؔ਺ͷݺͼग़࣌͠ʹݟ͑ΔͷͰԿΛҾ਺ͱ ͯ͠ड͚औΔͷ͔Θ͔Γ΍͘͢ͳΔ func rgbToHexString(red r:Int,

    green g:Int, blue b:Int) -> String { // ؔ਺಺Ͱ͸ɺ֤Ҿ਺ͷϩʔΧϧ໊Λ࢖༻ return String(format:"%02x%02x%02x", r, g, b) } let color = rgbToHexString(red: 255, green: 128, blue: 0) ͜Ε͕ ֎෦Ҿ਺໊ 
  6. σϑΥϧτҾ਺ w ؔ਺ͷఆٛ࣌ɺҾ਺ʹσϑΥϧτͰ஋ΛೖΕ͓͚ͯΔػ ೳͷ͜ͱ w ݺͼग़࣌͠ʹҾ਺ʹ஋͕ೖΒͳ͍৔߹͸σϑΥϧτͷ஋ ͕࢖༻͞ΕΔ func encloseText(text: String,

    prefix: String = "(", suffix: String = ")") -> String { return prefix + text + suffix } print(encloseText(text: "ΓΜ͝")) σϑΥϧτҾ਺ σϑΥϧτҾ਺ ݺͼग़࣌͠ʹলུͰ͖Δ
  7. Մม௕Ҿ਺ // จࣈྻதʹࢦఆͨ͠จࣈͷͲΕؚ͔͕·ΕΕ͹trueΛฦ͢ func containsCharacter(text: String, characters: Character...) -> Bool

    { for ch in characters { for t in text { if ch == t { return true } } } return false } containsCharacter("abcdefg", "i") // false containsCharacter("abcdefg", "g", "h", "i") // true ͜Ε͕Մม௕Ҿ਺
  8. JOPVUҾ਺ w Ҿ਺ͱͯ͠౉ͨ͠ม਺ͷมߋΛؔ਺ͷ֎ଆͰࢀরͰ͖Δػೳ w جຊతʹ4XJGUͰ͸Ҿ਺ͱͯ͠౉ͨ͠ม਺ͷ஋͕ॻ͖׵ΘΔ͜ͱ͸ͳ͍͕ɺ JOPVUΛ࢖͏͜ͱͰ࣮ݱ͢Δ w ଟ༻͢Δͱม਺ͷมԽΛ௥͏ͷ͕େมʹͳΔͷͰ࢖༻ʹ͸஫ҙ w ݸਓతʹ͋·Γ࢖͍ͨ͘ͳ͍

    func incrementBy(inc: Int, inout val1: Int, inout val2: Int) { val1 += inc val2 += inc } var val1 = 100 var val2 = 200 incrementBy(10, &val1, &val2) print("val1=\(val1), val2=\(val2)") // val1=110, val2=210