Skip to content

Commit be8f683

Browse files
committed
[docs] 0.3.0 문서 작성
1 parent 4f98d0d commit be8f683

File tree

1 file changed

+78
-21
lines changed

1 file changed

+78
-21
lines changed

README.md

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ Delegation is a Swift macro package that unlocks builder-style configuration for
99
## 주요 기능 (Features)
1010

1111
- `@Delegatable` 애트리뷰트 하나로 체이닝 가능한 빌더 메서드 자동 생성
12+
- `@Controllable` 애트리뷰트를 void 메서드에 붙여 체이닝 가능한 `Self` 반환 메서드 생성
1213
- `async`, `throws`, 다중 파라미터, `@Sendable` 등 클로저 특성 그대로 유지
1314
- 시스템 기본 언어에 맞춰 한국어/영어 진단 메시지 자동 출력
1415

1516
## 설치 (Installation)
1617

17-
- Swift Package Manager만 지원하며 Swift 5.9(Xcode 15.0) 이상이 필요합니다.
18+
- Swift Package Manager만 지원하며 Swift 5.9(Xcode 15.0) 이상이 필요합니다.
1819
Swift Package Manager only, requiring Swift 5.9 (Xcode 15.0) or newer.
19-
- `Package.swift``dependencies``targets` 섹션에 아래와 같이 추가하세요.
20+
- `Package.swift``dependencies``targets` 섹션에 아래와 같이 추가하세요.
2021
Add the package to the `dependencies` and `targets` sections as shown below.
2122

2223
```swift
@@ -40,11 +41,13 @@ let package = Package(
4041
)
4142
```
4243

43-
> 현재 최신 태그는 `0.2.0`이며 릴리스에 맞춰 갱신해 주세요.
44+
> 현재 최신 태그는 `0.2.0`이며 릴리스에 맞춰 갱신해 주세요.
4445
> The current release tag is `0.2.0`; bump it as you publish newer versions.
4546
4647
## 사용 방법 (Usage)
4748

49+
### @Delegatable
50+
4851
```swift
4952
import Delegation
5053

@@ -55,9 +58,11 @@ struct ContentView {
5558
}
5659
```
5760

58-
- 각 프로퍼티와 동일한 이름의 체이닝 메서드가 생성되어 클로저를 저장하고 `Self` 복사본을 반환합니다.
61+
- `@Delegatable`각 프로퍼티와 동일한 이름의 체이닝 메서드를 생성해 클로저를 저장하고 `Self` 복사본을 반환합니다.
5962
Each annotated property gains a matching builder method that assigns the closure and returns a new copy of `Self` for chaining.
60-
- `async`, `throws`, 다중 파라미터, `@Sendable` 등 클로저 특징이 그대로 유지됩니다.
63+
- 생성된 메서드에는 `@discardableResult`가 자동으로 붙으며, 클래스/액터처럼 참조 타입에서는 복사 없이 원본 인스턴스를 반환합니다.
64+
The generated builders are marked `@discardableResult`; class/actor contexts return `self` without copying while value types return a fresh instance.
65+
- `async`, `throws`, 다중 파라미터, `@Sendable` 등 클로저 특징이 그대로 유지됩니다.
6166
All closure traits—`async`, `throws`, multiple parameters, `@Sendable`, optionals—are preserved.
6267

6368
```swift
@@ -69,27 +74,54 @@ ContentView()
6974
}
7075
```
7176

77+
### @Controllable
78+
79+
```swift
80+
struct NumberController {
81+
private var number = 0
82+
var currentNumber: Int { number }
83+
84+
@Controllable
85+
private mutating func changeNumber(_ value: Int) {
86+
number = value
87+
}
88+
}
89+
90+
let controller = NumberController()
91+
.changeNumber(10)
92+
93+
print(controller.currentNumber) // 10
94+
```
95+
96+
- 반환 타입이 없는 메서드에 `@Controllable`을 붙이면 본문을 복사한 뒤 `Self`를 반환하는 빌더 메서드가 추가됩니다. 값 타입은 복사본을, 참조 타입은 원본 인스턴스를 그대로 반환합니다.
97+
Annotate void functions with `@Controllable` to synthesise a builder method that mirrors the body and returns `Self`; value types return a copy while reference types return the original instance.
98+
- `mutating`, `async`, `throws` 등 기존 선언의 효과는 새 메서드에도 유지됩니다.
99+
Existing modifiers such as `mutating`, `async`, and `throws` propagate to the generated method.
100+
- SwiftUI `View`처럼 `@State`를 사용하는 값 타입 샘플은 `Sources/DelegationClient/main.swift`에서 확인할 수 있습니다.
101+
See `Sources/DelegationClient/main.swift` for a SwiftUI `View` sample that updates `@State` through the generated builder.
102+
103+
72104
## 진단 메시지 (Diagnostics)
73105

74-
- 변수에만 적용할 수 있으며 `var` 키워드를 요구합니다.
106+
- 변수에만 적용할 수 있으며 `var` 키워드를 요구합니다.
75107
Use the macro on stored `var` properties only.
76-
- 타입 주석이 없거나 클로저가 아니면 컴파일 단계에서 오류가 발생합니다.
108+
- 타입 주석이 없거나 클로저가 아니면 컴파일 단계에서 오류가 발생합니다.
77109
Missing closure annotations result in compile-time diagnostics.
78-
- 시스템이 감지한 기본 언어 설정이 한국어(`ko`)이면 한국어, 그 외에는 영어로 경고/오류를 출력합니다.
110+
- 시스템이 감지한 기본 언어 설정이 한국어(`ko`)이면 한국어, 그 외에는 영어로 경고/오류를 출력합니다.
79111
Diagnostics localise automatically based on preferred languages (`ko` → Korean, otherwise English).
80112

81113
대표 오류 예시 Example messages:
82114

83-
- `@Delegatable는 변수에만 사용할 수 있습니다.`
115+
- `@Delegatable는 변수에만 사용할 수 있습니다.`
84116
`Apply @Delegatable to stored variables only.`
85-
- `@Delegatable는 var로 선언된 저장 프로퍼티에서만 사용할 수 있습니다.`
117+
- `@Delegatable는 var로 선언된 저장 프로퍼티에서만 사용할 수 있습니다.`
86118
`@Delegatable works only on stored properties declared with var.`
87-
- `@Delegatable는 클로저 타입에만 사용할 수 있습니다.`
119+
- `@Delegatable는 클로저 타입에만 사용할 수 있습니다.`
88120
`Use @Delegatable only with closure types.`
89121

90122
## SwiftUI 예제 (SwiftUI Example)
91123

92-
다음은 SwiftUI에서 체이닝 패턴을 구현한 예시입니다.
124+
다음은 SwiftUI에서 체이닝 패턴을 구현한 예시입니다.
93125
The snippet below demonstrates chaining in SwiftUI.
94126

95127
```swift
@@ -99,14 +131,20 @@ import Delegation
99131
struct ContentView: View {
100132
@Delegatable private var pushListView: (() -> Void)?
101133
@Delegatable private var buttonClicked: (() -> Void)?
134+
@State private var title = "Hello, world!"
135+
136+
@Controllable
137+
private func changeTitle(_ text: String) {
138+
title = text
139+
}
102140

103141
var body: some View {
104142
VStack(spacing: 16) {
105143
Image(systemName: "globe")
106144
.imageScale(.large)
107145
.foregroundColor(.accentColor)
108146

109-
Text("Hello, world!")
147+
Text(title)
110148

111149
Button("버튼") {
112150
buttonClicked?()
@@ -117,42 +155,58 @@ struct ContentView: View {
117155
pushListView?()
118156
}
119157
}
158+
159+
Button("타이틀 변경") {
160+
changeTitle("Delegation")
161+
}
120162
}
121163
.padding()
122164
}
123165
}
124166
```
125167

126-
체이닝된 확장자는 아래와 같이 클로저를 주입합니다.
168+
체이닝된 확장자는 아래와 같이 클로저를 주입합니다.
127169
Configure delegates via chaining as shown below.
128170

129171
```swift
130172
ContentView()
131173
.buttonClicked { print("buttonClicked 델리게이트가 호출되었습니다.") }
132174
.pushListView { print("pushListView 델리게이트가 호출되었습니다.") }
175+
.changeTitle("Delegation")
133176
```
134177

135-
- 패키지는 별도 실행 타깃을 포함하지 않으며, 위 코드는 문서용 예시입니다.
178+
- `@Controllable`이 생성한 빌더를 통해 SwiftUI 상태(`@State`)를 체이닝으로 갱신할 수 있습니다.
179+
Use the builder produced by `@Controllable` to update SwiftUI `@State` via chaining.
180+
- 패키지는 별도 실행 타깃을 포함하지 않으며, 위 코드는 문서용 예시입니다.
136181
The package ships without an executable sample target; the snippet above is for documentation only.
137182

138183
## UIKit 예제 (UIKit Example)
139184

140-
UIKit 환경에서도 동일하게 체이닝된 델리게이트 구성을 적용할 수 있습니다.
185+
UIKit 환경에서도 동일하게 체이닝된 델리게이트 구성을 적용할 수 있습니다.
141186
The same chaining pattern works in UIKit-based view controllers.
142187

143188
```swift
144189
import UIKit
145190
import Delegation
146191

147192
final class ListViewController: UIViewController {
148-
@Delegatable var showDetail: ((String) -> Void)?
149-
@Delegatable var presentSettings: (() -> Void)?
193+
@Delegatable private var showDetail: ((String) -> Void)?
194+
@Delegatable private var presentSettings: (() -> Void)?
195+
private var titleText = "목록"
196+
197+
@Controllable
198+
private func updateTitle(_ text: String) {
199+
titleText = text
200+
title = text
201+
}
150202

151203
override func viewDidLoad() {
152204
super.viewDidLoad()
153205

154206
view.backgroundColor = .systemBackground
155207

208+
updateTitle("리스트")
209+
156210
let button = UIButton(type: .system)
157211
button.setTitle("설정 열기", for: .normal)
158212
button.addAction(UIAction { [weak self] _ in
@@ -176,17 +230,20 @@ final class ListViewController: UIViewController {
176230
let controller = ListViewController()
177231
.showDetail { id in print("detail: \(id)") }
178232
.presentSettings { print("settings") }
233+
.updateTitle("목록 화면")
179234
```
180235

181-
- 샘플 코드는 문서용 예시이며, 실제 앱 구조에 맞춰 델리게이트 채택과 레이아웃을 조정하세요.
236+
- 클래스에서도 `@Controllable`이 생성한 체이닝 메서드로 내부 상태를 직접 갱신할 수 있습니다.
237+
The `@Controllable` builder lets reference types update their internal state while participating in the chain.
238+
- 샘플 코드는 문서용 예시이며, 실제 앱 구조에 맞춰 델리게이트 채택과 레이아웃을 조정하세요.
182239
The snippet is documentation-only; adapt delegate conformance and layout to your project needs.
183240

184241
## 플랫폼 요구 사항 (Platform Requirements)
185242

186-
- `Package.swift`는 Swift 5.9 매니페스트 형식을 사용하며 최소 지원 플랫폼은 `iOS 13 / macOS 10.15 / tvOS 13 / watchOS 6 / macCatalyst 13` 이상입니다.
243+
- `Package.swift`는 Swift 5.9 매니페스트 형식을 사용하며 최소 지원 플랫폼은 `iOS 13 / macOS 10.15 / tvOS 13 / watchOS 6 / macCatalyst 13` 이상입니다.
187244
The manifest targets Swift tools 5.9 with minimum deployment targets of iOS 13, macOS 10.15, tvOS 13, watchOS 6, and macCatalyst 13.
188245

189246
## 라이선스 (License)
190247

191-
이 패키지는 `LICENSE` 파일의 내용을 따릅니다.
248+
이 패키지는 `LICENSE` 파일의 내용을 따릅니다.
192249
Refer to the `LICENSE` file for license details.

0 commit comments

Comments
 (0)