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
More Decks by yuuxeno
See All by yuuxeno
DIKitで人間がクラス間の依存関係解決するのを終わらせる
yuuxeno
3
4.7k
iOS アプリ開発における Redux という可能性
yuuxeno
1
710
Other Decks in Programming
See All in Programming
すこし踏み込む CancellationToken
htkym
2
1.6k
パーソナライズPodcastを作った話
repunit11
0
120
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
310
Security issues being discussed on Web Platforms
petamoriken
0
1.4k
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
450
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
450
速習iPhone Duo対応
yuukiw00w
2
960
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.9k
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
300
SREの越境 / SRE Collaboration
y0hgi
2
300
Domain-Driven Transformation
hschwentner
2
2.3k
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
350
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
699
190k
From π to Pie charts
rasagy
1
390
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
320
Unsuck your backbone
ammeep
672
58k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
710
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
460
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
400
We Are The Robots
honzajavorek
0
390
Transcript
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