Skip to content

difference between "MVC" and "MVP" #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: mvc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'mvc' into mvp
  • Loading branch information
marty-suzuki committed Feb 11, 2021
commit 40358f6e71ddf4f00c637d86f2d9464d8047c0a3
324 changes: 109 additions & 215 deletions iOSDesignPatternSamples.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protocol FavoriteView: class {

final class FavoriteViewController: UIViewController, FavoriteView {
@IBOutlet private(set) weak var tableView: UITableView!

let presenter: FavoritePresenter
let dataSource: FavoriteViewDataSource

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Combine
import GithubKit
import UIKit

protocol SearchView: class {
func reloadData()
Expand Down Expand Up @@ -71,7 +72,7 @@ final class SearchViewController: UIViewController, SearchView {
func reloadData() {
tableView.reloadData()
}

func keyboardWillShow(with keyboardInfo: UIKeyboardInfo) {
view.layoutIfNeeded()
let extra = tabBarController?.tabBar.bounds.height ?? 0
Expand Down
36 changes: 24 additions & 12 deletions iOSDesignPatternSamples/Sources/UI/Search/SearchViewPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
// Copyright © 2017年 marty-suzuki. All rights reserved.
//

import Combine
import Foundation
import GithubKit
import NoticeObserveKit
import UIKit

protocol SearchPresenter: class {
var view: SearchView? { get set }
Expand All @@ -34,9 +35,12 @@ final class SearchViewPresenter: SearchPresenter {
return model.isFetchingUsers
}

private let model = SearchModel()
private let model = SearchModel(
sendRequest: ApiSession.shared.send,
asyncAfter: { DispatchQueue.global().asyncAfter(deadline: $0, execute: $1) }
)
private var isReachedBottom: Bool = false
private var pool = Notice.ObserverPool()
private var cancellables = Set<AnyCancellable>()

init() {
self.model.delegate = self
Expand Down Expand Up @@ -68,19 +72,27 @@ final class SearchViewPresenter: SearchPresenter {
}

func viewWillAppear() {
NotificationCenter.default.nok.observe(name: .keyboardWillShow) { [weak self] in
self?.view?.keyboardWillShow(with: $0)
}
.invalidated(by: pool)
NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)
.sink { [weak self] notification in
guard let info = UIKeyboardInfo(notification: notification) else {
return
}
self?.view?.keyboardWillShow(with: info)
}
.store(in: &cancellables)

NotificationCenter.default.nok.observe(name: .keyboardWillHide) { [weak self] in
self?.view?.keyboardWillHide(with: $0)
}
.invalidated(by: pool)
NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification)
.sink { [weak self] notification in
guard let info = UIKeyboardInfo(notification: notification) else {
return
}
self?.view?.keyboardWillHide(with: info)
}
.store(in: &cancellables)
}

func viewWillDisappear() {
pool = Notice.ObserverPool()
cancellables.removeAll()
}

func showLoadingView(on view: UIView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class UserRepositoryViewController: UIViewController, UserRepositoryView {
@IBOutlet private(set) weak var tableView: UITableView!
@IBOutlet private(set) weak var totalCountLabel: UILabel!

let loadingView = LoadingView.makeFromNib()
let loadingView = LoadingView()

let favoritePresenter: FavoritePresenter
let userRepositoryPresenter: UserRepositoryPresenter
Expand All @@ -31,7 +31,7 @@ final class UserRepositoryViewController: UIViewController, UserRepositoryView {
self.favoritePresenter = favoritePresenter
self.userRepositoryPresenter = userRepositoryPresenter
self.dataSource = UserRepositoryViewDataSource(presenter: userRepositoryPresenter)

super.init(nibName: UserRepositoryViewController.className, bundle: nil)
hidesBottomBarWhenPushed = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import GithubKit
import UIKit

protocol UserRepositoryPresenter: class {
var view: UserRepositoryView? { get set }
Expand Down Expand Up @@ -40,7 +41,7 @@ final class UserRepositoryViewPresenter: UserRepositoryPresenter {
private var isReachedBottom: Bool = false

init(user: User) {
self.model = RepositoryModel(user: user)
self.model = RepositoryModel(user: user, sendRequest: ApiSession.shared.send)
self.model.delegate = self
}

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.