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
Repository pattern in Swift
Search
naoty
April 20, 2016
Technology
3
6.3k
Repository pattern in Swift
potatotips #28
naoty
April 20, 2016
Tweet
Share
More Decks by naoty
See All by naoty
Modular API Client
naoty
1
400
Timepiece
naoty
0
3.5k
Contribution to Rails
naoty
0
4.3k
久々のRailsプロジェクトで導入した開発環境
naoty
2
1.1k
Report of DIYish programming activity
naoty
1
220
How to build gems for Rails
naoty
1
150
Qiita/Kobito vs ?
naoty
0
190
Other Decks in Technology
See All in Technology
2025年に挑戦したいこと
molmolken
0
160
Oracle Exadata Database Service(Dedicated Infrastructure):サービス概要のご紹介
oracle4engineer
PRO
0
12k
生成AI × 旅行 LLMを活用した旅行プラン生成・チャットボット
kominet_ava
0
160
Evolving Architecture
rainerhahnekamp
3
260
タイミーのデータ活用を支えるdbt Cloud導入とこれから
ttccddtoki
1
180
Goで実践するBFP
hiroyaterui
1
120
今から、 今だからこそ始める Terraform で Azure 管理 / Managing Azure with Terraform: The Perfect Time to Start
nnstt1
0
240
GoogleのAIエージェント論 Authors: Julia Wiesinger, Patrick Marlow and Vladimir Vuskovic
customercloud
PRO
0
160
月間60万ユーザーを抱える 個人開発サービス「Walica」の 技術スタック変遷
miyachin
1
140
完全自律型AIエージェントとAgentic Workflow〜ワークフロー構築という現実解
pharma_x_tech
0
350
TSのコードをRustで書き直した話
askua
3
210
【NGK2025S】動物園(PINTO_model_zoo)に遊びに行こう
kazuhitotakahashi
0
240
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
19
2.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
500
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
RailsConf 2023
tenderlove
29
970
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
240
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Speed Design
sergeychernyshev
25
740
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
Optimizing for Happiness
mojombo
376
70k
Agile that works and the tools we love
rasmusluckow
328
21k
BBQ
matthewcrist
85
9.4k
Bash Introduction
62gerente
610
210k
Transcript
/BPUP,BOFLP 3FQPTJUPSZ QBUUFSOJO4XJGU
None
ϦϙδτϦύλʔϯ w ϦϙδτϦͱɺσʔλͷऔಘɺอଘɺআͷͨΊ ͷΠϯλʔϑΣΠε w ϦϙδτϦΛͬͯσʔλʹΞΫηε͢Δɻ w ϝϞϦɺ3FBMNɺ"1*ͱ͍ͬͨόοΫΤϯυΛ Δඞཁ͕ͳ͘ͳΔɻ
ViewController RecipeRepository WebAPIRecipeRepository RealmRecipeRepository query model params JSON NSPredicate RealmObject
JO4XJGU protocol RecipeRepository { func find(id: UInt) -> Recipe? func
findAll(query: Query, sort: Sort) -> [Recipe] func save(recipes: [Recipe]) -> Recipe? func delete(recipes: [Recipe]) -> Recipe? }
JO4XJGU class MemoryRecipeRepository: RecipeRepository { let recipes = [ Recipe(id:
1, name: “…”), Recipe(id: 2, name: “…”), Recipe(id: 3, name: “…”), ] func find(id: UInt) -> Recipe? { recipes.filter { $0.id == id }.first } }
w σʔλͷΞΫηε͍͍ͩͨඇಉظ w ΫΤϦιʔτͲ͏ͬͯࢦఆ͢Δͷ͔ w 3FDJQF3FQPTJUPSZ $IFG3FQPTJUPSZ 6TFS3FQPTJUPSZʜͱࣅͨΑ͏ͳίʔυΛίϐϖ
͢Δ͜ͱʹͳΓͦ͏
ϦϙδτϦͰඇಉظॲཧΛ ͔͋ͭ͏
1SPNJTF protocol RecipeRepository { func find(id: UInt) -> Task<Void, Recipe,
ErrorType> func findAll(query: Query, sort: Sort) -> Task<Void, [Recipe], ErrorType> func save(recipes: [Recipe]) -> Task<Void, Recipe, ErrorType> func delete(recipes: [Recipe]) -> Task<Void, Recipe, ErrorType> }
ViewController RecipeRepository WebAPIRecipeRepository RealmRecipeRepository query model params JSON NSPredicate RealmObject
ViewController RecipeRepository WebAPIRecipeRepository RealmRecipeRepository Task<Void, Model, Error> params JSON NSPredicate
RealmObject query
൚༻తͳΫΤϦΛఆٛ͢Δ
OBPUZ"OZ2VFSZ let query = AnyQuery.Equal(key: “name”, value: “naoty”) query.predicate //=>
NSPredicate(format: "name == ‘naoty’") query.dictionary //=> ["name": “naoty”] let sort = AnySort.Ascending(key: “id”) sort.sortDescriptors //=> [NSSortDescriptor(key: "id", ascending: true)] sort.dictionary //=> ["sort": ["id"]]
OBPUZ"OZ2VFSZ protocol RecipeRepository { func find(id: UInt) -> Task<Void, Recipe,
ErrorType> func findAll(query: AnyQuery, sort: AnySort) -> Task<Void, [Recipe], ErrorType> func save(recipes: [Recipe]) -> Task<Void, Recipe, ErrorType> func delete(recipes: [Recipe]) -> Task<Void, Recipe, ErrorType> }
ViewController RecipeRepository WebAPIRecipeRepository RealmRecipeRepository Task<Void, Model, Error> params JSON NSPredicate
RealmObject query
ViewController RecipeRepository WebAPIRecipeRepository RealmRecipeRepository Task<Void, Model, Error> [String: AnyObject] JSON
NSPredicate RealmObject AnyQuery
൚༻తͳϦϙδτϦܕ Λఆٛ͢Δ
͜ΕͰ͖ͳ͍ protocol Repository { associatedtype Domain func find(id: Uint) ->
Task<Void, Domain, ErrorType> } let repository: Repository = MemoryRecipeRepository()
ܕফڈ struct AnyRepository<DomainType>: Repository { let _find: (id: UInt) ->
Task<Void, DomainType, ErrorType> init<T: Repository where T.Domain == DomainType>(_ repository: T) { _find = repository.find } func find(id: UInt) -> Task<Void, DomainType, ErrorType> { return _find(id) } } let repository = AnyRepository(MemoryRecipeRepository()) // repository: AnyRepository<Recipe>
ViewController RecipeRepository WebAPIRecipeRepository RealmRecipeRepository Task<Void, Model, Error> [String: AnyObject] JSON
NSPredicate RealmObject AnyQuery
ViewController AnyRepository<Recipe> WebAPIRecipeRepository RealmRecipeRepository Task<Void, Model, Error> [String: AnyObject] JSON
NSPredicate RealmObject AnyQuery
࣮ྫ w IUUQTHJUIVCDPNOBPUZ1MBZHSPVOE USFFNBTUFS3FQPTJUPSZ
Ԡ༻ྫΩϟογϡ
Ωϟογϡ w ϦϙδτϦ͔Βऔಘͨ݁͠ՌΛΩϟογϡ͍ͨ͠ɻ w Ωϟογϡʹͳ͚ΕผͷϦϙδτϦ͔Βऔಘͯ͠ɺ Ωϟογϡʹอଘ্ͨ͠Ͱฦ͢ɻ w Ωϟογϡʹ͋Εฦ͢ɻ w ྫϩάΠϯϢʔβʔͷऔಘͳͲ
͋Γ͕ͱ͏͍͟͝·ͨ͠