Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created January 5, 2018 12:57
Show Gist options
  • Save vialyx/100c85f78b41226df27620f845112709 to your computer and use it in GitHub Desktop.
Save vialyx/100c85f78b41226df27620f845112709 to your computer and use it in GitHub Desktop.
protocol ResourceType {
func load()
}
protocol PagginationProtocol {
var offset: UInt { get set }
var limit: UInt! { get set }
var hasMore: Bool { get }
func loadMore()
}
final class ProfileInteractor: ResourceType {
func load() {
// TODO: - Make URLRequest
print("\(self) load")
}
}
final class UsersListInteractor: ResourceType, PagginationProtocol {
var offset: UInt
var limit: UInt!
var hasMore: Bool
init() {
offset = 0
hasMore = true
}
func load() {
// TODO: - Make URLRequest
print("\(self) load")
}
func loadMore() {
offset = offset + 10
load()
print("\(self) loadMore \(offset)")
}
}
let profileInteractor = ProfileInteractor()
profileInteractor.load()
let usersListInteractor = UsersListInteractor()
usersListInteractor.limit = 30
usersListInteractor.loadMore()
if usersListInteractor.hasMore {
usersListInteractor.loadMore()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment