You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+78-21Lines changed: 78 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,14 +9,15 @@ Delegation is a Swift macro package that unlocks builder-style configuration for
9
9
## 주요 기능 (Features)
10
10
11
11
-`@Delegatable` 애트리뷰트 하나로 체이닝 가능한 빌더 메서드 자동 생성
12
+
-`@Controllable` 애트리뷰트를 void 메서드에 붙여 체이닝 가능한 `Self` 반환 메서드 생성
12
13
-`async`, `throws`, 다중 파라미터, `@Sendable` 등 클로저 특성 그대로 유지
13
14
- 시스템 기본 언어에 맞춰 한국어/영어 진단 메시지 자동 출력
14
15
15
16
## 설치 (Installation)
16
17
17
-
- Swift Package Manager만 지원하며 Swift 5.9(Xcode 15.0) 이상이 필요합니다.
18
+
- Swift Package Manager만 지원하며 Swift 5.9(Xcode 15.0) 이상이 필요합니다.
18
19
Swift Package Manager only, requiring Swift 5.9 (Xcode 15.0) or newer.
19
-
-`Package.swift`의 `dependencies`와 `targets` 섹션에 아래와 같이 추가하세요.
20
+
-`Package.swift`의 `dependencies`와 `targets` 섹션에 아래와 같이 추가하세요.
20
21
Add the package to the `dependencies` and `targets` sections as shown below.
21
22
22
23
```swift
@@ -40,11 +41,13 @@ let package = Package(
40
41
)
41
42
```
42
43
43
-
> 현재 최신 태그는 `0.2.0`이며 릴리스에 맞춰 갱신해 주세요.
44
+
> 현재 최신 태그는 `0.2.0`이며 릴리스에 맞춰 갱신해 주세요.
44
45
> The current release tag is `0.2.0`; bump it as you publish newer versions.
45
46
46
47
## 사용 방법 (Usage)
47
48
49
+
### @Delegatable
50
+
48
51
```swift
49
52
importDelegation
50
53
@@ -55,9 +58,11 @@ struct ContentView {
55
58
}
56
59
```
57
60
58
-
- 각 프로퍼티와 동일한 이름의 체이닝 메서드가 생성되어 클로저를 저장하고 `Self` 복사본을 반환합니다.
61
+
-`@Delegatable`은 각 프로퍼티와 동일한 이름의 체이닝 메서드를 생성해 클로저를 저장하고 `Self` 복사본을 반환합니다.
59
62
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` 등 클로저 특징이 그대로 유지됩니다.
61
66
All closure traits—`async`, `throws`, multiple parameters, `@Sendable`, optionals—are preserved.
62
67
63
68
```swift
@@ -69,27 +74,54 @@ ContentView()
69
74
}
70
75
```
71
76
77
+
### @Controllable
78
+
79
+
```swift
80
+
structNumberController {
81
+
privatevar number =0
82
+
var currentNumber: Int { number }
83
+
84
+
@Controllable
85
+
privatemutatingfuncchangeNumber(_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
+
72
104
## 진단 메시지 (Diagnostics)
73
105
74
-
- 변수에만 적용할 수 있으며 `var` 키워드를 요구합니다.
106
+
- 변수에만 적용할 수 있으며 `var` 키워드를 요구합니다.
75
107
Use the macro on stored `var` properties only.
76
-
- 타입 주석이 없거나 클로저가 아니면 컴파일 단계에서 오류가 발생합니다.
108
+
- 타입 주석이 없거나 클로저가 아니면 컴파일 단계에서 오류가 발생합니다.
77
109
Missing closure annotations result in compile-time diagnostics.
78
-
- 시스템이 감지한 기본 언어 설정이 한국어(`ko`)이면 한국어, 그 외에는 영어로 경고/오류를 출력합니다.
110
+
- 시스템이 감지한 기본 언어 설정이 한국어(`ko`)이면 한국어, 그 외에는 영어로 경고/오류를 출력합니다.
79
111
Diagnostics localise automatically based on preferred languages (`ko` → Korean, otherwise English).
80
112
81
113
대표 오류 예시 Example messages:
82
114
83
-
-`@Delegatable는 변수에만 사용할 수 있습니다.`
115
+
-`@Delegatable는 변수에만 사용할 수 있습니다.`
84
116
`Apply @Delegatable to stored variables only.`
85
-
-`@Delegatable는 var로 선언된 저장 프로퍼티에서만 사용할 수 있습니다.`
117
+
-`@Delegatable는 var로 선언된 저장 프로퍼티에서만 사용할 수 있습니다.`
86
118
`@Delegatable works only on stored properties declared with var.`
87
-
-`@Delegatable는 클로저 타입에만 사용할 수 있습니다.`
119
+
-`@Delegatable는 클로저 타입에만 사용할 수 있습니다.`
88
120
`Use @Delegatable only with closure types.`
89
121
90
122
## SwiftUI 예제 (SwiftUI Example)
91
123
92
-
다음은 SwiftUI에서 체이닝 패턴을 구현한 예시입니다.
124
+
다음은 SwiftUI에서 체이닝 패턴을 구현한 예시입니다.
93
125
The snippet below demonstrates chaining in SwiftUI.
0 commit comments