Skip to content

Commit

Permalink
chore: add file template to create View and Feature based on TCA
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed Rokon Uddin committed Sep 6, 2023
1 parent 8935593 commit a68ab8d
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ The templete used `.xcconfig` and `BuildConfiguration.plist` files to maintain d

You will have to manually configure the bundle id of the main target and test target.

## TCA Template Installation
All the Xcode custom template files are located in ~/Library/Developer/Xcode/Templates/ and grouped into sections by folder name. Create a folder with name `Custom Templates` manually or by running the following command from the terminal:

```
mkdir ~/Library/Developer/Xcode/Templates/Custom Templates
```

Now drag and drop the `TCA.xctemplate` that included with the repo to the `Custom Templates` directory. Now the TCA template can be selected from File Templates

![](assets/tca_template.gif)

## Contributing Code
Please refer to [Contributing Guidelines](https://github.com/monstar-lab-oss/swiftui-template-tca/blob/main/CONTRIBUTING.md) before participating.

Expand Down
Binary file added TCA.xctemplate/TemplateIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TCA.xctemplate/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions TCA.xctemplate/TemplateInfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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>DefaultCompletionName</key>
<string>File</string>
<key>Summary</key>
<string>This generates a new Feature.</string>
<key>Description</key>
<string>The template create a new Feature which is based on The Composable Architecture(TCA). It consists of a SwiftUI View and Feature file that implments the TCA Reducer.</string>
<key>Kind</key>
<string>Xcode.IDEKit.TextSubstitutionFileTemplateKind</string>
<key>Options</key>
<array>
<dict>
<key>Description</key>
<string>The name of the feature to create</string>
<key>Identifier</key>
<string>moduleName</string>
<key>Name</key>
<string>New Feature 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___View</string>
<key>Description</key>
<string>The view name</string>
<key>Identifier</key>
<string>viewName</string>
<key>Name</key>
<string>View Name:</string>
<key>Required</key>
<true/>
<key>Type</key>
<string>static</string>
</dict>
<dict>
<key>Default</key>
<string>___VARIABLE_moduleName___Feature</string>
<key>Description</key>
<string>The name of the feature</string>
<key>Identifier</key>
<string>featureName</string>
<key>Name</key>
<string>Name of Feature:</string>
<key>Required</key>
<true/>
<key>Type</key>
<string>static</string>
</dict>
</array>
<key>SortOrder</key>
<string>7</string>
</dict>
</plist>
66 changes: 66 additions & 0 deletions TCA.xctemplate/___FILEBASENAME___/___FILEBASENAME___Feature.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// ___FILENAME___
// ___PROJECTNAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
//___COPYRIGHT___
//

import Domain
import Commons
import Foundation
import ComposableArchitecture

public struct ___VARIABLE_moduleName___Feature: Reducer {

public struct State: Equatable {
public init() {}
}

public enum Action: BaseAction {

enum ViewAction: Equatable {
case onAppear

}

enum InlyingAction: Equatable {

}

enum DelegateAction: Equatable {

}

case view(ViewAction)
case inlying(InlyingAction)
case delegate(DelegateAction)
}

public func reduce(into state: inout State, action: Action) -> Effect<Action> {
switch action {
case .view(let action):
switch action {
case .onAppear:
return .none

}
case .inlying(let action):
switch action {

}
case .delegate(let action):
switch action {

}
}
}

// Remove commented code if not needed
// public var body: some Reducer<State, Action> {
//
// Reduce { state, action in
//
// }
// }
}
29 changes: 29 additions & 0 deletions TCA.xctemplate/___FILEBASENAME___/___FILEBASENAME___View.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ___FILENAME___
// ___PROJECTNAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
//___COPYRIGHT___
//

import SwiftUI
import Commons
import Resources
import ComposableArchitecture

public struct ___VARIABLE_moduleName___View: View {
let store: StoreOf<___VARIABLE_moduleName___Feature>

public init(store: StoreOf<___VARIABLE_moduleName___Feature>) {
self.store = store
}

public var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
Text("Hello World!!!")
.onAppear {
viewStore.send(.onAppear)
}
}
}
}
Binary file added assets/tca_template.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a68ab8d

Please sign in to comment.