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
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
260
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
6
3.3k
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.7k
「AI時代、配布するPythonコードをどう守るか: 難読化の実験と判断軸」 #PyconJP2026
pkshadeck
PRO
2
190
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
150
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
360
AIとGame Jamで、ゲームを完成させた話
takahirosaeki
0
110
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
130
GKE で Pod の見方を変えたら、スケールアウト時の挙動を真に捉えられた話
stkk
0
110
スマート反転とウェブアクセシビリティ
camiha
0
170
Featured
See All Featured
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
190
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Color Theory Basics | Prateek | Gurzu
gurzu
0
460
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
510
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
370
We Are The Robots
honzajavorek
0
360
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
490
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
500
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
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