문득 TCA로 개발을 하려다가 TCA의 경우 특정한 템플릿이 존재한다는 것을 알게 되었고, 이것을 Xcode로 빠르게 만들 수 없을까? 하는 생각에서 템플릿을 적용해 보기로 했다.
🎉 결과물
개선이 필요하겠지만 첫번째 템플릿은 아래와 같이 Feature이라는 이름을 넣게 되면 자동으로 @Reducer struct Feature { ... } 와 FeatureView 가 생성된다. Feature 대신 다른이름을 넣으면 그 이름 그대로 만들어 준다. Preview도 간단하게 만들었다.
🚧 과정
과정은 생각보다 요상하게 안되는 것들이 있어서 조금 고생한 것 같다. 우선 Swift 코드는 아래와 같이 만들었다. ___VARIABLE_productName___ 은 내가 입력한 텍스트 값으로 대치된다.
import ComposableArchitecture
@Reducer
struct ___VARIABLE_productName___ {
@ObservableState
struct State: Equatable {
// TODO: Define state properties
}
enum Action {
// TODO: Define actions
}
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
// TODO: Handle actions
}
}
}
}
import SwiftUI
import ComposableArchitecture
struct ___VARIABLE_productName___View: View {
let store: StoreOf<___VARIABLE_productName___>
var body: some View {
// TODO: Build your UI
Text("___VARIABLE_productName___ View")
}
}
#Preview {
___VARIABLE_productName___View(
store: Store(initialState: ___VARIABLE_productName___.State()) {
___VARIABLE_productName___()
}
)
}
살짝 골치가 아팠던 부분은 아래와 같은 TemplateInfo.plist 파일이었다...! 😭
<?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>Identifier</key>
<string>TCA</string>
<key>Description</key>
<string>A feature module using The Composable Architecture (TCA).</string>
<key>SortOrder</key>
<string>0</string>
<key>DefaultCompletionName</key>
<string>Feature</string>
<key>Platforms</key>
<array>
<string>com.apple.platform.iphoneos</string>
</array>
<key>Options</key>
<array>
<dict>
<key>Identifier</key>
<string>productName</string>
<key>Name</key>
<string>New Feature Name:</string>
<key>Description</key>
<string>The name of the TCA feature to create</string>
<key>Type</key>
<string>text</string>
<key>Default</key>
<string>Feature</string>
<key>Required</key>
<true/>
</dict>
</array>
<key>Files</key>
<array>
<string>___VARIABLE_productName___.swift</string>
<string>___VARIABLE_productName___View.swift</string>
</array>
</dict>
</plist>
productName으로 identifier를 해주지 않으면 값을 입력하고 나서도 SaveAs: 파일명으로 파일명을 또다시한번 입력해줘야 한다. 나는 featureName으로 해도 될 줄 알았는데, 꼭 네이밍을 productName을 해야 되는 것이여서 삽질을 좀 한 것 같다.
그리고 아이콘이 없으면 심심하니까 나름대로 아이콘도 넣어줬다. (큰 의미는 없다... 🥸)
만들고 나니 괜히 뿌듯한 느낌... 그리고 여러가지 Feature를 만들 때 생산성도 올라갈 것 같다 :) 🎉 나중에도 자주 작성하는 보일러 플레이트 코드는 이렇게 템플릿화 시켜놔야 겠다는 생각이 들었다. (이것도 나중에 AI에 등록해놓고 ~~~만들어줘로 대체할 수 있을듯!)
🍱 사용 방법
아래의 파일을 받고 (2025.05.08 추가 수정)
터미널을 열고 아래의 경로로 이동한다. Finder로 이동해도 상관 없음
open ~/Library/Developer/Xcode/
들어가서 Templates라는 폴더가 없다면 만들어주고, 그 아래에는 Custom같은 아무 폴더를 만들고 다운받은 .xctemplate 폴더를 넣어주면 된다.
아무 폴더나 만들라는 것은 나같은 경우 Custom을 만들었는데 그렇게 되면 아래와 같이 Custom 섹션에 TCA Feature이라는 템플릿이 들어가게 된다. (역시 아이콘이 있어야 심심하지 않다)
'→ Xcode' 카테고리의 다른 글
[Xcode] nw_connection_copy_connected_local_endpoint... 오류 (0) | 2024.02.06 |
---|---|
[Xcode] Thread Sanitizer (0) | 2024.01.11 |
[Xcode] 내 Xcode 프로젝트는 몇줄일까? (0) | 2024.01.07 |
[Xcode] SwiftLint 적용하기 (1) | 2024.01.06 |
[Xcode] 원하는 폰트가 적용되지 않을때 (1) | 2023.11.24 |