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
140
Qiita/Kobito vs ?
naoty
0
190
Other Decks in Technology
See All in Technology
生成AIのガバナンスの全体像と現実解
fnifni
1
180
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
2
260
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
32k
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
110
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
280
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
480
AIのコンプラは何故しんどい?
shujisado
1
190
なぜCodeceptJSを選んだか
goataka
0
160
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
150
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
181
21k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Designing Experiences People Love
moore
138
23k
It's Worth the Effort
3n
183
28k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Faster Mobile Websites
deanohume
305
30k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Speed Design
sergeychernyshev
25
670
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
GraphQLとの向き合い方2022年版
quramy
44
13k
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 ྫϩάΠϯϢʔβʔͷऔಘͳͲ
͋Γ͕ͱ͏͍͟͝·ͨ͠