Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Objective-C と比べて Swift が強力だと感じた4つの点
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
yuuxeno
June 20, 2017
Programming
320
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Objective-C と比べて Swift が強力だと感じた4つの点
yuuxeno
June 20, 2017
Transcript
42 slides
Objective-C ͱൺͯ Swift ͕ ڧྗͩͱײͨ͡4ͭͷ
Yusuke Minami • @yuuxeno • iOS ΤϯδχΞ
let , var
mutable (Մม) immutable (ෆม) Λ໌֬ʹ۠ผͰ͖Δ
mutable(Մม) ͷϠό͞ var item = Item(id: 1, name: “Swift”) item
= Item(id: 1, name: “Objective-C") ⛏ ৭ʑͳॲཧ ⛏
mutable ͳͷɾɾɾ • Ͳ͜Ͱ͕มΘΔͷ͔ΛৗʹಡΈख͕ҙࣝ͢ Δඞཁ͕͋ΔͷͰՄಡੑ͕͍ • ࠓͲ͏͍͏ঢ়ଶͳͷ͔ΛৗʹಡΈख͕ҙࣝ͢ Δඞཁ͕͋ΔͷͰͭΒ͍
ίʔυΛಡΜͰ͍Δ࣌ؒͷେ෦Λ mutable ͳͷʹඅ͍ͯ͠Δ • ͜ͷঢ়ଶ͕มΘͬͨ࣌ʹॲཧͲ͏มΘΔͷ ͔ ? • ͦΕʹΑͬͯผͷঢ়ଶͲ͏มΘΔͷ͔ ?
• ҎԼϧʔϓ
όά ՄಡੑԼ ֦ுੑԼ
͍͍ͩͨίΠπͷ͍ͤ
શ͕ͯ immutable ͷੈք
࠷ߴ !
ݱ࣮
ΞϓϦঢ়ଶͩΒ͚ɾɾɾ
શ෦ແ͘͢ͷແཧͳͷͰ
ແବͳঢ়ଶΛ࡞Βͳ͍ let isImmutable = true var text: String if isImmutable
{ text = "immutable" } else { text = "mutable" } let isImmutable = true let text: String = { if isImmutable { return "immutable" } else { return "mutable" } }()
ঢ়ଶΛཧ͢Δ •Redux !
ϠόΠͭʹ var ҹΛ͚ͭΔ final class ItemViewController: UIViewController { let ɾɾɾ
let itemDataStore = ItemDataStore() var item: Item? let totalItem = 100 let ɾɾɾ
• Objective-C ʹ immutable Λදݱग़དྷΔ const ͕͋ͬͨɺ mutable Λ໌ࣔతʹදݱ ग़དྷΔͷͳ͔ͬͨ
• ϓϩύςΟͷ readwrite লུՄೳͩͬͨ • let -> var ͷॻ͖͑ίʔυϨϏϡʔͰؾͮ ͖͍͢
ͦͷ ຊʹඞཁͰ͔͢ ? ͦͷ ຊʹ৻ॏʹѻͬͯ·͔͢ ?
var = = औѻҙ
MutableProperty Variable
map, flatMap, filter, reduce
mutable ͳͷΛݮΒͤΔ let items = [Item(id: 1, price: 100), Item(id:
2, price: 200), Item(id: 3, price: 300)] var fetchedItems = [Item]() for item in items { if item.price >= 200 { fetchedItems.append(item) } } let fetchedItems = items.filter { $0.price >= 200 }
ԿΛ͍ͯ͠Δ͔͕ҰͰ͔Δ let items = [Item(id: 1, price: 100), Item(id: 2,
price: 200), Item(id: 3, price: 300)] var fetchedItems = [Item]() for item in items { if item.price >= 200 { fetchedItems.append(item) } } let fetchedItems = items.filter { $0.price >= 200 }
ݟ௨͕͘͢͠͝ྑ͘ͳΔ • mutable ͳͷͲ͜Ͱঢ়ଶ͕มΘΔͷ͔ҙ ࣝ͢Δඞཁ͕͋ΔͷͰಡΈʹ͍͘ • ιʔείʔυ͕͋ΔఔͷنʹͳΔͱɺશ ͯͷ෦ʹ͍ͭͯࡉ෦·Ͱ۩ମతʹԿΛͯ͠ ͍Δ͔ΛѲ͢Δͷແཧ ->
งғؾ͚ͩͰ ௫Έ͍ͨ
var, for, if map, flatMap, filter, reduce
Optional
nil Λ୳ཱྀ͢ʹඅ͕࣌ؒ͢େ෯ʹݮͬͨ
ఆ֎ͷ݁Ռ ɾɾɾCSFBLQPJOU /4-PH OJM OJM OJM
ͳ͓ͥલ ( nil ) ͕ͦ͜ʹ͍ΔΜͩ ?
ͳͥͩΖ͏ • nil νΣοΫΛΕΔͱ͙͢ʹఆ֎ͷॲཧ͕ ߦΘΕΔ • nil νΣοΫΕΔͱఆ֎ͷ͕ͲΜͲΜਂ ͍ͱ͜ΖʹྲྀΕ͍ͯ͘ •
ͳ͔ͥ͋Γ͑ͳ͍ͱ͜Ζʹ nil ͕ೖͬͯΔ
Optional • ͋Δ͔͠Εͳ͍ɺͳ͍͔͠Εͳ͍ͱ͍͏ ࣄʹରͯ͠໌֬ͳܕ͕Ͱ͖ͨ • ৗʹॻ͖खʹ nil Λҙࣝͤ͞ɺߟ͑ͤ͞Δ ( ͜
ͷมʹ্࣮ nil ͕དྷΔͷ͔ͳͲ ) • ΛऔΓग़͢߹ʹnil Λඞͣҙࣝͤ͞Δ
ϛεͬͯ nil Λྲྀͯ͠͠·͏ࣄ͕গͳ͘ͳͬͨ
ଘࡏ͢Δͱଘࡏ͢Δ͔͠Εͳ͍ શ͘ผͷ͜ͱͩͬͨ
protocol extension
ɾɾɾܧঝ $MBTT" $MBTT# #BTF$MBTT $MBTT$
ඞཁҎ্ͷͷʹґଘ͢Δ • ܧঝݩΫϥεͷҰ෦ͷػೳΛ͍͍͕ͨͨΊʹɺ༷ʑͳػೳ Λ࣋ͬͨܧঝݩͷΫϥεશͯʹґଘ͢Δ • Ұ෦ͷػೳΛมߋ͠Α͏ͱ͢ΔͱɺͦͷΫϥεͷܧঝઌͷΫ ϥεશͯνΣοΫ͢Δඞཁ͕͋Δ -> গ͠ͷมߋͰӨڹൣ ғ͕େ͖͍ͷͰ؆୯ʹϦϑΝΫλϦϯάͰ͖ͳ͍
• ܧঝݩͷΫϥε͕༷ʑͳׂΛ࣋ͭͨΊݟ௨͕͘͢͠͝ѱ͘ ͳΔ ( ܧঝઌͷΫϥεΛݟͳ͍ͱͲ͏͍͏ҙਤͰ࣮͞Εͨ ͷ͔͕Θ͔Βͳ͍)
ϦϑΝΫλϦϯάͰ͖ͳ͍ͷͰ ޙͲΜͲΜଠ͍ͬͯ͘ͷΈ
ɾɾɾద߹ $MBTT" $MBTT# QSPUPDPMFYUFOTJPO $MBTT$
protocol extension ͳΒ • ΫϥεΑΓࡉ͔͍ύʔπʹ͚ΒΕ࠶ར༻ੑ͕ߴ ͍ • ΫϥεΑΓநͷߴ͍ protocol ʹґଘ͢ΔͨΊม
ߋʹڧ͍ • Өڹൣғͦͷ protocol extension ͕࣮ݱ͢Δػೳ ʹґଘ͍ͯ͠Δ෦ʹݶΒΕΔͨΊϦϑΝΫλϦϯ ά͕༰қ
None
ࢀߟ • SwiftͷOptionalͷϕετϓϥΫςΟε http://qiita.com/ koher/items/8b6156c8263b9b23c43c
More Decks by yuuxeno
See All by yuuxeno
DIKitで人間がクラス間の依存関係解決するのを終わらせる
yuuxeno
3
4.7k
iOS アプリ開発における Redux という可能性
yuuxeno
1
720
Other Decks in Programming
See All in Programming
ruby/uri meets WHATWG
jinroq
0
140
SONY CISC-NEWS NWS-1750 + NWB-225 ハードウェアメンテとフレームバッファカラー対応 / KOF2026
tsutsui
0
140
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
340
Distance field of Julia set
kinakomoti321
0
330
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
210
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
230
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
17
9.6k
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
110
Spec-driven Development with AI
simas
PRO
0
2.3k
imagewebp()の向こう側: WebPはなぜ JPEG・PNGより軽いのか
yuzneri
0
150
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
270
Featured
See All Featured
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
48k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
330
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
Designing Experiences People Love
moore
143
24k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
690
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
590
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
2
4k
Faster Mobile Websites
deanohume
310
32k
Designing for Performance
lara
612
70k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
860
Principles of Awesome APIs and How to Build Them.
keavy
128
18k