Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated the file templates to include the data source template.
* 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
Showing
9 changed files
with
191 additions
and
7 deletions.
There are no files selected for viewing
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
61
Template/File templates/DataSource.xctemplate/TemplateInfo.plist
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,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> |
38 changes: 38 additions & 0 deletions
38
Template/File templates/DataSource.xctemplate/___FILEBASENAME___DataSource.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,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
44
Template/System/Sources/Protocols/DataSourceProtocol.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,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) | ||
} | ||
} |
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 @@ | ||
// | ||
// 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] | ||
} | ||
} |
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
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