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
実践Protocol-Extension
Search
Shinji Kobayashi
October 06, 2016
Programming
84
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
実践Protocol-Extension
Shinji Kobayashi
October 06, 2016
More Decks by Shinji Kobayashi
See All by Shinji Kobayashi
5分でできる UITableViewのDrag & Drop
gentlesoft
0
470
自社コンテンツ配信 のためのWebView Tips
gentlesoft
2
5.6k
UIKitDynamicsの活用法
gentlesoft
0
620
iOS9のUIKitDynamics
gentlesoft
0
50
SwiftでUIKitDynamics
gentlesoft
0
59
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
200
Other Decks in Programming
See All in Programming
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
1.1k
えっ!!コードを読まずに開発を!?
hananouchi
0
200
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
130
フィードバックで育てるAI開発
kotaminato
1
120
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
360
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
370
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.5k
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
490
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
140
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.9k
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
150
Featured
See All Featured
A Tale of Four Properties
chriscoyier
163
24k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
300
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
390
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
350
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
330
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
How to train your dragon (web standard)
notwaldorf
97
6.7k
Mobile First: as difficult as doing things right
swwweet
225
10k
RailsConf 2023
tenderlove
30
1.5k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.4k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
260
Transcript
࣮ફProtocol-Extension Shinji Kobayashi TOPLOG / Gentlesoft shibuya.swift #5
Swift3.0ରԠ ਐΜͰ·͔͢ʁ
ࢲ·ͩख͔ͣͰ͢ɻ (2.3ରԠ͕Α͏͘ऴΘͬͨͱ͜ΖͰ͢)
ͳͥ͜Ε΄ͲͷखؒΛ ͔͚ͯSwiftΛ͏ͷ͔ʁ •Objective-CΑΓ؆ܿʹॻ͚Δ͔Βʁ • ؔܕͷαϙʔτʁ •දݱྗͷߴ͍enumʁ •Protocol-Extensionʂ
Protocol-Extension ͷԿ͕͍͍ʁ
ϓϩάϥϜͷ࣮ํ๏ ΛมԽͤͨ͞
Ͳ͏͍͏෩ʹʁ
֮͑ͯཉ͍͠ศརػೳ •associatedtype •where Self: Hogehoge •Selfܕ
NameɿShinji Kobayashi Twitterɿ@gentlejkov GentleSoft Who are you? http://gentlesoft.net
Work https://toplog.co.jp/ TOPLOG iOS Engineer
TOPLOG APP 2016/3/1 ver.1.0.0 Now ver.2.1.3 100% pure Objective-C 70%
Swift
TOPLOG APP ΩϡϨʔγϣϯ ΦϦδφϧهࣄ
TOPLOG APP ΦϦδφϧهࣄ දࣔ͢Δσʔλҧ͏͕ػೳࣅ͍ͯΔ ΩϡϨʔγϣϯ
TOPLOG APP ΩϡϨʔγϣϯ ΦϦδφϧهࣄදࣔ ࠂදࣔ ΦϦδφϧهࣄ
TOPLOG APP ΩϡϨʔγϣϯ ΦϦδφϧهࣄදࣔProtocol ࠂදࣔProtocol ΦϦδφϧهࣄ
RANKING MY CLIP TOPLOG APIͷΓཁૉ͕एׯҧ͏(ߏಉ͡) Ϧετͷ࣮ํ๏ಉ͡ʢαʔόଆͰΓସ͑ʣ ΦϦδφϧهࣄදࣔ
ΦϦδφϧهࣄදࣔ
ΦϦδφϧهࣄදࣔ APIͷΓͷڞ௨෦ΛProtocolͰఆٛ͠ associatedtypeͰઃఆͨ͠ܕContentsΛ੍͢Δ ContentsܕͷσʔλΛ࣋ͭΫϥεͱͯ͠ ৼΔ͏͜ͱ͕Ͱ͖Δ
ΦϦδφϧهࣄදࣔ Extension
ΦϦδφϧهࣄදࣔ Extension ΦϦδφϧهࣄΛදࣔ͢ΔͨΊͷ ϏδωεϩδοΫΛ·ͱΊͨͷ
ࠂදࣔ Protocol-Extension ࠂΛදࣔ͢ΔͨΊͷ ϏδωεϩδοΫΛ·ͱΊͨͷ
ͭ·Γ Protocol-Extension
ϏδωεϩδοΫΛ ViewController͔Β ࣗવʹΓग़ͤΔ
ExtensionΛUIViewControllerͱͯ͠ѻ͍͍ͨ લड़ͨ͠Protocolݪଇ UIViewControllerͰ࣮͞ΕΔ Extensionͷܕ੍
Extensionͷܕ੍
ExtensionΛUIViewControllerͰ੍ ͜ͷExtensionͰ selfUIViewControllerͱͯ͠ѻ͑Δ Extensionͷܕ੍
ΦϦδφϧهࣄදࣔProtocolͱࠂදࣔProtocol ͷ྆ํΛ࣮͢ΔViewController͕͋Δ ্هProtocolͷ྆ํΛ࣮͢Δ߹ Ұ෦ϩδοΫΛมߋ͍ͨ͠ Extensionͷܕ੍
ඪ४࣮ ಛघ࣮ Extensionͷܕ੍
ඪ४࣮ ಛघ࣮ ಛఆͷProtocolΛ࣮͍ͯ͠Δ࣌ͷ ผϩδοΫ Extensionͷܕ੍
ܕ੍ʹΑΔಛघ࣮ ͷҙ ProtocolʹએݴΛ͓͔ͯ͠ͳ͍ͱ ϙϦϞϑΟοΫʹಈ࡞͠ͳ͍
Selfܕ Protocolʹ͓͍ͯࣗࣗΛࢦ͢ ܕͷ͜ͱ ࣗࣗͷΦϒδΣΫτΛฦ͢ ExtensionͷϝιουΛ࣮Ͱ͖Δ
ڞ௨ͷFactoryϝιου
֮͑ͯཉ͍͠ศརػೳ ϓϩάϥϜΛࣗવʹ ܕ҆શʹ͢ػೳ •associatedtype •where Self: Hogehoge •Selfܕ
·ͱΊ •Protocol-ExtensionΛ͏ࣄͰɺϏδωεϩδοΫ ΛࣗવʹViewController͔ΒΓग़͠ɺඞཁʹԠ ֤ͯ͡ΫϥεʹదԠͤ͞Δࣄ͕Մೳͱͳͬͨ •assosiatedtype, where, SelfܕͳͲͷػೳʹΑΓܕ҆ શͰ෭࡞༻ͷগͳ͍ϩδοΫͷڞ௨Խ͕Ͱ͖Δ