-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from emadhegab/develop
v1.1
- Loading branch information
Showing
260 changed files
with
2,553 additions
and
20,641 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...ject.xcworkspace/contents.xcworkspacedata → ...kage.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...oteApp/Base.lproj/LaunchScreen.storyboard → ...pleApp/Base.lproj/LaunchScreen.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// BaseDatasources.swift | ||
// TypiCodeUsers | ||
// | ||
// Created by Mohamed Hegab on 10/29/18. | ||
// Copyright © 2019 MHNetwork All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
protocol BaseTableDataSource: class, UITableViewDelegate, UITableViewDataSource { | ||
associatedtype ItemType | ||
var items: [ItemType] { get set } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// BaseRouter.swift | ||
// TypiCodeUsers | ||
// | ||
// Created by Mohamed Hegab on 10/29/18. | ||
// Copyright © 2019 MHNetwork All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
|
||
protocol BaseRouter { | ||
func route() | ||
} | ||
class DefaultBaseRouter: BaseRouter { | ||
|
||
func route() { | ||
|
||
guard let rootVC = UIApplication.shared.delegate?.window??.rootViewController else { | ||
|
||
UIApplication.shared.delegate?.window??.makeKeyAndVisible() | ||
UIApplication.shared.delegate?.window??.rootViewController = | ||
UINavigationController(rootViewController: UserRouter.createModule()) | ||
|
||
return | ||
} | ||
|
||
UserRouter.route(from: rootVC, animated: false) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
ExampleApp/Classes/Features/Posts/Datasources/Cells/PostCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// PostCell.swift | ||
// TypiCodeUsers | ||
// | ||
// Created by Mohamed Hegab on 10/29/18. | ||
// Copyright © 2019 MHNetwork All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class PostCell: UITableViewCell { | ||
|
||
@IBOutlet weak var titleLabel: UILabel! | ||
|
||
@IBOutlet weak var bodyLabel: UILabel! | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
ExampleApp/Classes/Features/Posts/Datasources/Cells/PostCell.xib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> | ||
<device id="retina4_7" orientation="portrait"> | ||
<adaptation id="fullscreen"/> | ||
</device> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="166" id="KGk-i7-Jjw" customClass="PostCell" customModule="TypiCodeUsers" customModuleProvider="target"> | ||
<rect key="frame" x="0.0" y="0.0" width="558" height="166"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | ||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM"> | ||
<rect key="frame" x="0.0" y="0.0" width="558" height="165.5"/> | ||
<autoresizingMask key="autoresizingMask"/> | ||
<subviews> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tSf-Yx-IC3"> | ||
<rect key="frame" x="20" y="25" width="518" height="33.5"/> | ||
<fontDescription key="fontDescription" type="boldSystem" pointSize="28"/> | ||
<nil key="textColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Y2K-9X-CpZ"> | ||
<rect key="frame" x="20" y="68.5" width="518" height="86.5"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<nil key="textColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<constraints> | ||
<constraint firstItem="Y2K-9X-CpZ" firstAttribute="trailing" secondItem="H2p-sc-9uM" secondAttribute="trailingMargin" id="5sn-CA-Ked"/> | ||
<constraint firstItem="tSf-Yx-IC3" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="M32-R4-HPv"/> | ||
<constraint firstItem="Y2K-9X-CpZ" firstAttribute="bottom" secondItem="H2p-sc-9uM" secondAttribute="bottomMargin" id="Qcr-zr-XjI"/> | ||
<constraint firstItem="tSf-Yx-IC3" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="14" id="eg2-el-qFZ"/> | ||
<constraint firstAttribute="trailingMargin" secondItem="tSf-Yx-IC3" secondAttribute="trailing" id="hih-VI-6pk"/> | ||
<constraint firstItem="Y2K-9X-CpZ" firstAttribute="top" secondItem="tSf-Yx-IC3" secondAttribute="bottom" constant="10" id="jAX-OP-JSc"/> | ||
<constraint firstItem="Y2K-9X-CpZ" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="oyS-gU-XJt"/> | ||
</constraints> | ||
</tableViewCellContentView> | ||
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/> | ||
<connections> | ||
<outlet property="bodyLabel" destination="Y2K-9X-CpZ" id="H8z-QX-8Mn"/> | ||
<outlet property="titleLabel" destination="tSf-Yx-IC3" id="Hub-q3-9HE"/> | ||
</connections> | ||
<point key="canvasLocation" x="238.40000000000001" y="148.42578710644679"/> | ||
</tableViewCell> | ||
</objects> | ||
</document> |
33 changes: 33 additions & 0 deletions
33
ExampleApp/Classes/Features/Posts/Datasources/PostsDatasources.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// PostsDatasources.swift | ||
// TypiCodeUsers | ||
// | ||
// Created by Mohamed Hegab on 10/29/18. | ||
// Copyright © 2019 MHNetwork All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class PostDatasources: NSObject, BaseTableDataSource { | ||
|
||
var items: [Post] = [] | ||
|
||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return items.count | ||
} | ||
|
||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
guard let cell = tableView.dequeueReusableCell(withIdentifier: PostCell.reuseId) as? PostCell else { return UITableViewCell(frame: CGRect.zero) } | ||
let post = self[indexPath] | ||
cell.titleLabel.text = post.title | ||
cell.bodyLabel.text = post.body | ||
return cell | ||
} | ||
} | ||
|
||
|
||
extension PostDatasources { | ||
subscript(indexPath: IndexPath) -> Post { | ||
return items[indexPath.row] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Post.swift | ||
// TypiCodeUsers | ||
// | ||
// Created by Mohamed Hegab on 10/29/18. | ||
// Copyright © 2019 MHNetwork All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Post: Codable { | ||
let title: String | ||
let body: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// PostInteractor.swift | ||
// TypiCodeUsers | ||
// | ||
// Created Mohamed Hegab on 10/29/18. | ||
// Copyright © 2019 MHNetwork All rights reserved. | ||
// | ||
|
||
class PostInteractor: PostInteractorProtocol { | ||
|
||
weak var presenter: PostPresenterProtocol? | ||
func getPosts(userId: String, onCompletion: @escaping ([Post]) -> Void, onError: @escaping (NetworkError) -> Void) { | ||
let dispatcher = Container.shared.createNetworkDispatcher() | ||
let getPostsTask = GetPostsTasks<[Post]>(userId: userId) | ||
|
||
getPostsTask.execute(in: dispatcher) { (result) in | ||
switch result { | ||
case .success(let posts): | ||
onCompletion(posts) | ||
case .failure(let error): | ||
onError(error) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// PostPresenter.swift | ||
// TypiCodeUsers | ||
// | ||
// Created Mohamed Hegab on 10/29/18. | ||
// Copyright © 2019 MHNetwork All rights reserved. | ||
// | ||
|
||
|
||
import UIKit | ||
|
||
class PostPresenter: PostPresenterProtocol { | ||
|
||
weak private var view: PostViewProtocol? | ||
var interactor: PostInteractorProtocol? | ||
|
||
init(interface: PostViewProtocol, interactor: PostInteractorProtocol?) { | ||
self.view = interface | ||
self.interactor = interactor | ||
} | ||
|
||
func getPosts(userId: String) { | ||
interactor?.getPosts(userId: userId, onCompletion: { (posts) in | ||
DispatchQueue.main.async { [weak self] in | ||
self?.view?.reloadData(posts: posts) | ||
} | ||
}, onError: { (error) in | ||
print(error) | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// PostProtocols.swift | ||
// TypiCodeUsers | ||
// | ||
// Created Mohamed Hegab on 10/29/18. | ||
// Copyright © 2019 MHNetwork All rights reserved. | ||
// | ||
|
||
//MARK: Presenter - | ||
protocol PostPresenterProtocol: class { | ||
func getPosts(userId: String) | ||
} | ||
|
||
//MARK: Interactor - | ||
protocol PostInteractorProtocol: class { | ||
|
||
var presenter: PostPresenterProtocol? { get set } | ||
func getPosts(userId: String, onCompletion: @escaping ([Post]) -> Void, onError: @escaping (NetworkError) -> Void) | ||
} | ||
|
||
//MARK: View - | ||
protocol PostViewProtocol: class { | ||
|
||
var presenter: PostPresenterProtocol? { get set } | ||
func reloadData(posts: [Post]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// PostRouter.swift | ||
// TypiCodeUsers | ||
// | ||
// Created Mohamed Hegab on 10/29/18. | ||
// Copyright © 2019 MHNetwork All rights reserved. | ||
// | ||
|
||
|
||
import UIKit | ||
|
||
class PostRouter { | ||
|
||
weak var viewController: UIViewController? | ||
|
||
static func createModule(userId: String) -> UIViewController { | ||
let view = PostViewController(userId: userId) | ||
let interactor = PostInteractor() | ||
let router = PostRouter() | ||
let presenter = PostPresenter(interface: view, interactor: interactor) | ||
|
||
view.presenter = presenter | ||
interactor.presenter = presenter | ||
router.viewController = view | ||
|
||
return view | ||
} | ||
|
||
static func route(userId: String, from: UIViewController, animated: Bool) { | ||
from.navigationController?.pushViewController(createModule(userId: userId), animated: animated) | ||
} | ||
} |
Oops, something went wrong.