Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mobile Programming Control Flow 2
Search
yuichiro_takahashi
October 15, 2018
Technology
0
50
Mobile Programming Control Flow 2
MobileProgrammingの授業で使うスライドです!
yuichiro_takahashi
October 15, 2018
Tweet
Share
More Decks by yuichiro_takahashi
See All by yuichiro_takahashi
App Clip - in a nutshell
yuichirokato
0
310
巨大な機能を VIPER + MicroViewController でいい感じに実装した話
yuichirokato
1
770
Mobile Programming Protocol Extension
yuichirokato
0
77
Mobile Programming Protocol
yuichirokato
0
79
Mobile Programming enum
yuichirokato
0
160
Mobile Programming Optional
yuichirokato
0
130
Mobile Programming Struct
yuichirokato
0
120
Mobile Programming Initializer Beta
yuichirokato
0
120
Mobile Programming Inheritance
yuichirokato
0
140
Other Decks in Technology
See All in Technology
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
210
20241220_S3 tablesの使い方を検証してみた
handy
3
240
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
730
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
160
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
840
.NET 9 のパフォーマンス改善
nenonaninu
0
530
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
120
コンテナセキュリティのためのLandlock入門
nullpo_head
2
320
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
150
Featured
See All Featured
Writing Fast Ruby
sferik
628
61k
The Cult of Friendly URLs
andyhume
78
6.1k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
RailsConf 2023
tenderlove
29
940
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Adopting Sorbet at Scale
ufuk
73
9.1k
Mobile First: as difficult as doing things right
swwweet
222
9k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Building an army of robots
kneath
302
44k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Transcript
੍ޚߏจ2 MOBILEPROGRAMMING OCT, 15TH
ςΩετ ੍ޚߏจʂ ▸ iffor-inͳͲذ܁Γฦ͠ॲཧΛಛఆͷจʹߏԽͨ͠ͷ ▸ ϓϩάϥϜͷߏ ॱ࣍ɺબɺ෮ͷࡾͭʹྨ͞ΕΔ ▸ ͜ΕΒΛΈ߹Θͤͯϓϩάϥϛϯά͢Δํ๏ΛߏԽϓϩάϥ ϛϯάͱݺͿ
▸ ࠓճ܁Γฦ͠ͷߏจʹߜͬͯͬͯߦ͖·͢ ▸ ݴޠʹΑͬͯforwhileͱ͍͏ߏจ͕ଘࡏ͠ͳ͍(or ͨͩͷγ ϯλοΫεγϡΨʔ)
1. FOR-IN
ςΩετ FOR-INจ ▸ ܁Γฦ͠ॲཧΛ͢Δͱ͖ͷجຊతͳߏจ ▸ ߏจ for <ม> in <Array
or Range> { /* loop */ } ▸ Լهͷforͱ۠ผ͢ΔͨΊʹ for-inͱݺΕ·͢ ▸ for (int i = 0; i <= 10, i++) { /* loop */ } ▸ ͷΑ͏ͳߏจSwift 3.0 Ҏ߱ഇࢭ͞Ε·ͨ͠ ▸ ͜ͷΑ͏ͳforจΛC-style forͱݺͼ·͢ ▸ forจಛఆͷճ܁Γฦ͠ॲཧΛ͍ͨ͠ͱ͍͏Α͏ͳ߹ʹΑ͍͘·͢
ςΩετ ͳΜͰC-STYLE FOR ফ͑ͨʁ ▸ ؆ܿʹ͍͏ͱSwiftΒ͘͠ͳ͍͔Β ▸ CݴޠܦݧऀҎ֎ʹΘ͔Γʹ͍͘͠ ▸ ॳΊͯSwiftΛֶͿਓʹͱ֮ͬͯ͑ʹ͍͘
▸ ΠϯΫϦϝϯτɺσΫϦϝϯτʹΑΔ͋Δ͠ for (let i = 0; i <= 10; i++) { // loop... for (let j = 0; j <= 10;, i++) { print("it's a infinity loop!") } }
ͰͲ͏ͬͯ ϧʔϓͤ͞Δʁ
1-1.RANGE
ςΩετ RANGE(ൣғԋࢉࢠ)Λ͏ ▸ Ұ൪؆୯ͳΓํ ▸ switchͷ࣌ʹग़͖ͯͨΑ͏ʹ 0…10 ͱͯ͠ 0 ~
10·Ͱͷ Sequence(Array)Λ࡞ ▸ ͦΕΛfor-inͱΈ߹ΘͤΔ // Range let range = 0...10 for number in range { print("number: \(number)") }
ςΩετ FOR-IN STLIDE ▸ for-inͱ stlide Λ༻͢Δ͜ͱͰִؒΛ։͚ͯϧʔϓͤ͞Δ ͜ͱ͕Ͱ͖·͢ // 0͔Β10·ͰೋͭͱͼͰϧʔϓ
for number in stride(from: 0, to: 10, by: 2) { print("number: \(number)") }
1-2. ARRAY
ςΩετ ARRAYΛ͏ ▸ ͜ΕඇৗʹΦʔιυοΫεͳΓํ ▸ ఆٛࡁΈͷarrayʹରͯ͠for-inΛ͏ ▸ indexͰΞΫηε͢Δํ๏ʹൺ Array ͷൣғ֎ʹΞΫηε
ͯ͠͠·͏͜ͱ͕ͳ͍ͨΊ҆શ // Array let array = ["sunday", "monday", "tuesday", "wednsday", "thursday", "friday", "Saturday"] for number in array { print("number: \(number)") }
1-3.DICTIONARY
ςΩετ DICTIONARYΛ͏ ▸ ͜ΕׂͱΦʔιυοΫεͳΓํ ▸ ఆٛࡁΈͷdictionaryʹରͯ͠for-inΛ͏ ▸ key, value ͷܗʹͳ͍ͬͯΔͨΊ
for ͷҾೋͭʹͳΔ // Dictionary let dic = ["Animal": "Cat", "Fruit": "Banana"] for (key, value) in dic { print("key: \(key)") print("value: \(value)") }
2. WHILE
ςΩετ WHILEจ ▸ ܁Γฦ͠ॲཧΛ͢Δͱ͖ͷجຊతͳߏจ ▸ ߏจ while <ϧʔϓ݅> { /*
loop */ } ▸ whileจಛఆͷ݅ʹϚον͢Δ·Ͱ܁Γฦ͠ॲཧΛͨ͠ ͍࣌ʹ͏ var count = 0 var total = 0 while count < 5 { count += 1 total += count } print("count: \(count) total: \(total)")
3. ੍ޚసૹ
ςΩετ ੍ޚసૹ(CONTROL TRANSFER STATEMENTS)ʁ ▸ ੍ޚసૹ(Control Transfer Statements)ϓϩάϥϜͷॲཧ ΛΛ͋Δॴ͔ΒผͷॴʹҠ͢ػೳͷ͜ͱ ▸
ྫ͑continue break, switchͷfallthroughͳͲ͕͋Δ ▸ ؔͷreturn Τϥʔॲཧʹग़ͯ͘Δ throw ಉ͡ ▸ ࠓճbreakͱcontinueʹߜ͓ͬͯΛ͠·͢
3-1.BREAK
ςΩετ BREAK ▸ ଞͷݴޠಉ༷Swiftʹ break ͕͋Γ·͢ ▸ ಛఆͷ݅ͷ࣌ʹϧʔϓ͔Βൈ͚͍ͨ߹ʹbreakΛ༻͠ ·͢ for
i in 0...10 { // 11ճϧʔϓͤ͞·͢ɻ if i >= 3 { // i ͕ 3 Ҏ্ʹͳͬͨͱ͖ʹൈ͚Δ break } print(i) }
3-2. CONTINUE
ςΩετ CONTINUE ▸ ଞͷݴޠಉ༷Swiftʹ continue ͕͋Γ·͢ ▸ ಛఆͷ݅ͷ࣌ʹॲཧΛεΩοϓ͍ͨ͠߹continueΛ ༻͠·͢ ▸
breakͱҧ͍loopΛൈ͚Δ͜ͱ͋Γ·ͤΜ for i in 0...10 { if i % 3 == 0 { // 3ͷഒͷ࣌εΩοϓ continue } print(i) }
͓·͚
ςΩετ FORWHILEΛΘͳ͍ʁ ▸ ಄Ͱগ͓ͨ͠͠௨ΓݴޠʹΑͬͯforwhile͕ଘࡏ͠ ͳ͍Ͱ͢ ▸ ͰͲ͏ͬͯ܁Γฦ͠Λදݱ͢ΔͷͰ͠ΐ͏͔ʁ ▸ ํ๏͍͔ͭ͋͘ΓҰͭߴ֊ؔΛ͏ํ๏ ▸
͏Ұͭ࠶ؼؔΛ͏ํ๏Ͱ͢
͓·͚: ߴ֊ؔ
ςΩετ ߴ֊ؔʁ ▸ ؔΛҾʹͱͬͨΓɺؔΛฦؔ͢ ▸ ͍͜͠ͷͰࠓৄ͘͠આ໌͠·ͤΜ ▸ ܁Γฦ͠ͷͨΊͷ༗໊Ͳ͜ΖͰ map,
forEach ͳͲ͕͋ Γ·͢ ▸ for-inΛ͏ํ๏ΑΓ؆ܿʹॻ͘͜ͱ͕Ͱ͖·͢
ςΩετ ͨͱ͑ʁ ▸ ஈͷϦετʹରͯ͠ফඅ੫Λ͔͚ͨޙͷஈͷϦετΛੜ ͢ΔྫΛߟ͑·͢ ▸ ͜ΕΛfor-inͰॻ͘ͱ࣍ͷΑ͏ʹͳΓ·͢
ςΩετ ϥϯμϜʹੜͨ͠ͷഒΛٻΊΔ // ফඅ੫ let taxRate = 0.08 // ஈͷϦετ
let prices: [Double] = [10000, 9800, 34570, 29800, 114514] // ·ۭͣͷྻΛੜ var newPrices = [Double]()
ςΩετ ϥϯμϜʹੜͨ͠ͷഒΛٻΊΔ // ফඅ੫ let taxRate = 0.08 // ஈͷϦετ
let prices: [Double] = [10000, 9800, 34570, 29800, 114514] // ·ۭͣͷྻΛੜ var newPrices = [Double]() // for-inͰҰྻ͔ΒऔΓग़ͯ͠ɾɾɾ for price in prices { }
ςΩετ ϥϯμϜʹੜͨ͠ͷഒΛٻΊΔ // ফඅ੫ let taxRate = 0.08 // ஈͷϦετ
let prices: [Double] = [10000, 9800, 34570, 29800, 114514] // ·ۭͣͷྻΛੜ var newPrices = [Double]() // for-inͰҰྻ͔ΒऔΓग़ͯ͠ɾɾɾ for price in prices { let newPrice = price * taxRate newPrices.append(newPrice) // ·ͨྻೖΕΔʂ }
߇͑Ίʹݴͬͯ ໘
ςΩετ ߴ֊ؔΛͬͨ߹ ▸ ߴ֊ؔ(ࠓճmap)Λ͏ͱ࣍ͷΑ͏ʹॻ͘͜ͱ͕Ͱ͖· ͢ // ফඅ੫ let taxRate =
0.08 // ஈͷϦετ let prices: [Double] = [10000, 9800, 34570, 29800, 114514]
ςΩετ ߴ֊ؔΛͬͨ߹ ▸ ߴ֊ؔ(ࠓճmap)Λ͏ͱ࣍ͷΑ͏ʹॻ͘͜ͱ͕Ͱ͖· ͢ // ফඅ੫ let taxRate =
0.08 // ஈͷϦετ let prices: [Double] = [10000, 9800, 34570, 29800, 114514] let newPrices = prices.map { $0 * taxRate } // ʂ
None
͍ʂ
ςΩετ ͍ʂ ▸ ߴ֊ؔΛ͏ͱͱͯ؆ܿʹ͔͚·͢ ▸ ࠓճͬͨmapͱ͍͏ߴ֊ؔྻͷதʹॱ൪ʹड͚ औͬͨॲཧΛద༻͠ɺ৽͍͠ྻΛੜ͢ΔؔͰ͢ ▸ { $0
* taxRate } ͷ෦͕ྻͷதશͯʹద༻͞Εɺͦͷ݁ Ռ͕৽͍͠ྻͱͳΓ·͢ ▸ ߴ֊ؔΛ͏͜ͱͰ༨ܭͳίʔυΛল͖ɺͲΜͳॲཧΛ ͍ͨ͠ͷ͔ʁͱ͍͏෦ʹूதͰ͖·͢
ͪΐͬͱͬ ͯʂ (TWITTERฒײ)
ͦͦؔͬͯ ͳΜ͚ͩͬʁ