0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

普段使用しているRepositoryのテンプレート

Posted at

Repositoryはデータ通信を行うもので、
主にAPIを叩いたり、ローカルのDBにアクセスするときに使用しています。

戻り値がVoidになっておりますが、
データを取得したらここに戻り値にそれをセットします。
あくまで、データをCreate(生成)、Read(読み取り)、Update(更新)、Delete(削除)のが責務にさせることがポイントです。

import UIKit
import RxCocoa
import RxSwift

protocol AuthRepositoryInjectable {
    var authRepositoryImpl: AuthRepository { get }
}

extension AuthRepositoryInjectable {
    var authRepositoryImpl: AuthRepository {
        return AuthRepositoryImpl.shared
    }
}

protocol AuthRepository {
    func doSomething() -> Single<Element>
}

class AuthRepositoryImpl: AuthRepository {
    let bag = DisposeBag()
    static var shared = AuthRepositoryImpl()
    private init() {}
    
    func doSomething() -> Single<Void> {
        return Single<Void>.just(())
    }
}


テンプレートも作りました!
https://github.com/yosuke1985/Clean-MVVM-Generator/blob/main/Clean%20MVVM/Repository.xctemplate/___FILEBASENAME___Repository.swift

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?