Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<%
// Usage:
// 1. Add the following protocol to your project:
// protocol StoryboardInitializable where Self: UIViewController {
// static func instantiateFromStoryboard() -> Self
// }
//
// 2. Conform view controllers to it.
// 3. Use this template with Sourcery: https://github.com/krzysztofzablocki/Sourcery
//
//
// Author: Arek Holko, MIT LICENSE
// https://github.com/fastred/StoryboardDependencyInjectionTemplates
-%>
<% types.implementing.StoryboardInitializable.forEach(function(type){ -%>
// MARK: - <%= type.name -%> - StoryboardDependencyInjection
extension <%= type.name -%> {
<%
var allProperties = [];
var currentType = type;
while (currentType) {
allProperties.push.apply(allProperties, currentType.storedVariables);
currentType = currentType.supertype;
}
var properties = allProperties.filter(function(property) {
return property.isImplicitlyUnwrappedOptional &&
!property.attributes.IBOutlet &&
["internal", "public", "open"].indexOf(property.writeAccess) > -1
})
-%>
static func makeFromStoryboard(
<% properties.forEach(function(property, index){ -%>
<%= property.name -%>: <%= property.typeName.unwrappedTypeName -%><% if (index !== properties.length - 1) { %>,<% } %>
<% }) -%>
) -> <%= type.name -%> {
let viewController = <%= type.name %>.instantiateFromStoryboard()
viewController.setDependencies(
<% properties.forEach(function(property, index){ -%>
<%= property.name -%>: <%= property.name -%><% if (index !== properties.length - 1) { %>,<% } %>
<% }) -%>
)
return viewController
}
func setDependencies(
<% properties.forEach(function(property, index){ -%>
<%= property.name -%>: <%= property.typeName.unwrappedTypeName -%><% if (index !== properties.length - 1) { %>,<% } %>
<% }) -%>
) {
<% properties.forEach(function(property){ -%>
self.<%= property.name %> = <%= property.name %>
<% }) -%>
}
}
<% }) %>