minsone.github.io

[Swift] private protocol로 파일 내부 공통 구현 숨기기 (opens in new tab)

코드를 정리하다 보면, 같은 프로토콜을 채택한 타입이 여러 개 있는데 실제 구현을 열어보면 거의 똑같은 경우가 있습니다\. 차이라고는 type 같은 값 하나뿐이고, 메서드 구현은 전부 복붙인 상태입니다\. 예를 들어 Processor Plugin 코드가 아래처럼 생겼다고 해봅시다\. // File: InvestPlugin\.swift enum InvestPlugin \{ static let list : \[ ProcessorPlugin \] = \[ Home \(\), BondList \(\), ProductDetail \(\) \] \} extension InvestPlugin \{ struct Home : ProcessorPlugin \{ var type : PluginType \{ \. 채권\_홈 \} func run \( info : PluginInfo \) -\> Result Void , PluginRunError \> \{ guard let runner = Runne...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help