Skip to content

Commit

Permalink
* Updated the file templates to include the data source template.
Browse files Browse the repository at this point in the history
* Added the DataSourceProtocol and SectionProtocol files to the System framework.
* Corrected the Router implementations.
  • Loading branch information
Domagoj Kulundžić committed Oct 5, 2019
1 parent 72b1f66 commit db2d9fd
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 7 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions Template/File templates/DataSource.xctemplate/TemplateInfo.plist
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Kind</key>
<string>Xcode.IDEFoundation.TextSubstitutionFileTemplateKind</string>
<key>Description</key>
<string>Scene data source.</string>
<key>Summary</key>
<string>Scene data source.</string>
<key>SortOrder</key>
<string>30</string>
<key>AllowedTypes</key>
<array>
<string>public.swift-source</string>
</array>
<key>DefaultCompletionName</key>
<string>Scene</string>
<key>MainTemplateFile</key>
<string>___FILEBASENAME___.swift</string>
<key>Options</key>
<array>
<dict>
<key>Description</key>
<string>The name of the module to create</string>
<key>Identifier</key>
<string>moduleName</string>
<key>Name</key>
<string>Module name:</string>
<key>NotPersisted</key>
<true/>
<key>Required</key>
<true/>
<key>Type</key>
<string>text</string>
</dict>
<dict>
<key>Default</key>
<string>___VARIABLE_moduleName___</string>
<key>Identifier</key>
<string>productName</string>
<key>Type</key>
<string>static</string>
</dict>
<dict>
<key>Default</key>
<string>___VARIABLE_moduleName___DataSource</string>
<key>Description</key>
<string>Data source name</string>
<key>Identifier</key>
<string>dataSourceName</string>
<key>Name</key>
<string>Data source name:</string>
<key>Required</key>
<true/>
<key>Type</key>
<string>static</string>
</dict>
</array>
</dict>
</plist>
@@ -0,0 +1,38 @@
//
// ___FILENAME___
// ___PROJECTNAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// ___COPYRIGHT___
//

import UIKit

enum ___VARIABLE_dataSourceName___Item {
case <#item#>
}

enum ___VARIABLE_dataSourceName___Section: SectionProtocol {
case <#section#>([___VARIABLE_dataSourceName___Item])

var items: [___VARIABLE_dataSourceName___Item] {
switch self {
case .<#section#>(let items):
return items
}
}
}

class ___VARIABLE_dataSourceName___DataSource: DataSourceProtocol {
private(set) lazy var sections = [___VARIABLE_dataSourceName___Section]()

init() {
buildSections()
}
}

private extension ___VARIABLE_dataSourceName___DataSource {
func buildSections() {
sections.removeAll()
}
}
44 changes: 44 additions & 0 deletions Template/System/Sources/Protocols/DataSourceProtocol.swift
@@ -0,0 +1,44 @@
//
// DataSourceProtocol.swift
// O2O
//
// Created by Domagoj Kulundzic on 17/07/2018.
// Copyright © 2018 Martian & Machine. All rights reserved.
//

import Foundation

protocol DataSourceProtocol {
associatedtype Section: SectionProtocol
var sections: [Section] { get }
var isEmpty: Bool { get }
}

extension DataSourceProtocol {
var isEmpty: Bool {
guard numberOfSections() > 0 else {
return true
}
guard sections.first(where: { !$0.items.isEmpty }) != nil else {
return true
}
return false
}

func numberOfSections() -> Int {
return sections.count
}

func numberOfItems(in section: Int) -> Int {
guard let section = sections[safe: section] else { return 0 }
return section.isCollapsed ? 0 : section.items.count
}

func section(at index: Int) -> Section? {
return sections[safe: index]
}

func item(at indexPath: IndexPath) -> Section.Item? {
return section(at: indexPath.section)?.item(at: indexPath.item)
}
}
25 changes: 25 additions & 0 deletions Template/System/Sources/Protocols/SectionProtocol.swift
@@ -0,0 +1,25 @@
//
// SectionProtocol.swift
// O2O
//
// Created by Domagoj Kulundzic on 17/07/2018.
// Copyright © 2018 Martian & Machine. All rights reserved.
//

import Foundation

protocol SectionProtocol {
associatedtype Item
var items: [Item] { get }
var isCollapsed: Bool { get }
}

extension SectionProtocol {
var isCollapsed: Bool {
return false
}

func item(at index: Int) -> Item? {
return items[safe: index]
}
}
16 changes: 16 additions & 0 deletions Template/Template.xcodeproj/project.pbxproj
Expand Up @@ -55,6 +55,8 @@
482201BD22982422003319F0 /* System.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 482201A822982422003319F0 /* System.framework */; };
482201BE22982422003319F0 /* System.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 482201A822982422003319F0 /* System.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
482201CF2298252D003319F0 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 482201CE2298252D003319F0 /* LaunchScreen.storyboard */; };
488240552349447000CB6FFE /* SectionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 488240532349447000CB6FFE /* SectionProtocol.swift */; };
488240562349447000CB6FFE /* DataSourceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 488240542349447000CB6FFE /* DataSourceProtocol.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -214,6 +216,8 @@
482201B722982422003319F0 /* SystemTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemTests.swift; sourceTree = "<group>"; };
482201B922982422003319F0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
482201CE2298252D003319F0 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
488240532349447000CB6FFE /* SectionProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionProtocol.swift; sourceTree = "<group>"; };
488240542349447000CB6FFE /* DataSourceProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSourceProtocol.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -538,6 +542,7 @@
482201C822982451003319F0 /* Sources */ = {
isa = PBXGroup;
children = (
488240522349446600CB6FFE /* Protocols */,
480E55FF229BEFC20031BDF7 /* AttributedStringBuilder.swift */,
480E5602229BEFE20031BDF7 /* Broadcast.swift */,
480E5601229BEFE20031BDF7 /* BroadcastObjectWrapper.swift */,
Expand Down Expand Up @@ -633,6 +638,15 @@
path = Scenes;
sourceTree = "<group>";
};
488240522349446600CB6FFE /* Protocols */ = {
isa = PBXGroup;
children = (
488240542349447000CB6FFE /* DataSourceProtocol.swift */,
488240532349447000CB6FFE /* SectionProtocol.swift */,
);
path = Protocols;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -990,12 +1004,14 @@
buildActionMask = 2147483647;
files = (
480E56BE229C14970031BDF7 /* ExampleNavigationViewController.swift in Sources */,
488240552349447000CB6FFE /* SectionProtocol.swift in Sources */,
480E55F3229BEE6F0031BDF7 /* UICollectionView-Template.swift in Sources */,
480E55FC229BEF550031BDF7 /* URL-Template.swift in Sources */,
480E55FA229BEF430031BDF7 /* Collection-Template.swift in Sources */,
480E5689229C04BD0031BDF7 /* ExampleContentView.swift in Sources */,
480E55F2229BEE6F0031BDF7 /* UIColor-Template.swift in Sources */,
480E568C229C04BD0031BDF7 /* ExampleViewController.swift in Sources */,
488240562349447000CB6FFE /* DataSourceProtocol.swift in Sources */,
480E5692229C05F10031BDF7 /* ExampleTodosWorker.swift in Sources */,
480E55F0229BEE6F0031BDF7 /* UITableView-Template.swift in Sources */,
480E56BD229C14970031BDF7 /* ExampleNavigationRouter.swift in Sources */,
Expand Down
Expand Up @@ -16,11 +16,11 @@ protocol ExampleNavigationRouterDelegate: class {
func exampleNavigationRouterUnwindBack()
}

class ExampleNavigationRouter: Router {
weak var viewController: UIViewController?
class ExampleNavigationRouter {
weak var viewController: ExampleNavigationViewController?
weak var delegate: ExampleNavigationRouterDelegate?

static func createModule(delegate: ExampleNavigationRouterDelegate?) -> UIViewController {
static func createModule(delegate: ExampleNavigationRouterDelegate?) -> ExampleNavigationViewController {
let view = ExampleNavigationViewController()
let interactor = ExampleNavigationInteractor()
let router = ExampleNavigationRouter()
Expand Down
8 changes: 4 additions & 4 deletions Template/Template/App/Scenes/Example/ExampleRouter.swift
Expand Up @@ -17,11 +17,11 @@ protocol ExampleRouterDelegate: class {
func exampleRouterRequestedUnwind()
}

class ExampleRouter: Router {
weak var viewController: UIViewController?
class ExampleRouter {
weak var viewController: ExampleViewController?
weak var delegate: ExampleRouterDelegate?

static func createModule(delegate: ExampleRouterDelegate?) -> UIViewController {
static func createModule(delegate: ExampleRouterDelegate?) -> ExampleViewController {
let view = ExampleViewController()
let interactor = ExampleInteractor()
let router = ExampleRouter()
Expand All @@ -30,7 +30,7 @@ class ExampleRouter: Router {
let presenter = ExamplePresenter(interface: view, interactor: interactor, router: router)
view.presenter = presenter
interactor.presenter = presenter
return UINavigationController(rootViewController: view)
return view
}
}

Expand Down

0 comments on commit db2d9fd

Please sign in to comment.