<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>h_jeha.log</title>
        <link>https://velog.io/</link>
        <description>...</description>
        <lastBuildDate>Wed, 20 Jul 2022 05:48:40 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>h_jeha.log</title>
            <url>https://velog.velcdn.com/images/h_jeha/profile/ec94b26c-3ff2-4362-846d-a55ea6d66da3/image.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. h_jeha.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/h_jeha" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[네트워크-EndPoint [후회 - SwiftUI 전환기(1)]]]></title>
            <link>https://velog.io/@h_jeha/%EB%84%A4%ED%8A%B8%EC%9B%8C%ED%81%AC-EndPoint-%ED%9B%84%ED%9A%8C-SwiftUI-%EC%A0%84%ED%99%98%EA%B8%B01</link>
            <guid>https://velog.io/@h_jeha/%EB%84%A4%ED%8A%B8%EC%9B%8C%ED%81%AC-EndPoint-%ED%9B%84%ED%9A%8C-SwiftUI-%EC%A0%84%ED%99%98%EA%B8%B01</guid>
            <pubDate>Wed, 20 Jul 2022 05:48:40 GMT</pubDate>
            <description><![CDATA[<h2 id="후회---swiftui-전환기1">후회 - SwiftUI 전환기(1)</h2>
<h2 id="네트워크-endpoint">네트워크 EndPoint</h2>
<p>네트워크 EndPoint를 생성하는 구조를 개선해봤다.</p>
<h3 id="기존-네트워크-구조">기존 네트워크 구조</h3>
<h4 id="httpservice--http-통신을-담당하는-타입">HTTPService : HTTP 통신을 담당하는 타입</h4>
<pre><code class="language-swift">func fetch(_ path: APIPath, with coinSymbol: String) -&gt; Observable&lt;Data&gt; {
    // 1. EndPoint 생성
    let path = &quot;\(endPoint)/\(path.path)/\(coinSymbol)_\(path.paymentCurrency)&quot;
        ...
}</code></pre>
<h4 id="1-endpoint-생성">1. EndPoint 생성</h4>
<p>매개변수로 받은 <code>APIPath</code>는 열거형으로 Bithumb Public API 별 Case를 가지고 있다.
Case별 path만 가지고 있고, <code>*특정 코인(CoinSymbol)은 fetch() 메서드의 매개변수로 따로 받아</code>서 EndPoint를 생성하고 있다.</p>
<h4 id="1-1-endpoint-생성-개선점">1-1. EndPoint 생성 개선점</h4>
<p><code>*어떤 코인을 요청할 지는 fetch() 메서드의 매개변수로 따로 받아</code>에서 개선점을 발견할 수 있다. 하나의 EndPoint를 만드는데 <code>path</code>는 <code>APIPath 열거형</code>에서, <code>CoinSymbol</code>은 <code>fetch() 메서드의 매개변수</code>로 받고 있다. 이는 코드의 응집도가 떨어진다 판단했다.</p>
<h4 id="1-2-endpoint-생성-개선">1-2. EndPoint 생성 개선</h4>
<p>Alamofire의 <a href="https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#routing-requests">URLRequestConvertible</a>를 참고했다.</p>
<p><strong>개선 후 코드</strong></p>
<pre><code class="language-swift">enum APIRouter {

    // MARK: - API Cases

    case ticker(coinSymbol: String)
    case transactionHistory(coinSymbol: String)
    case candlestick(coinSymbol: String)

    // MARK: - Base URL

    var baseURL: URL {
        return URL(string: &quot;https://api.bithumb.com/public&quot;)!
    }

    // MARK: - Methods

    enum HTTPMethod: CustomStringConvertible {
        case get

        var description: String {
            switch self {
            case .get:
                return &quot;GET&quot;
            }
        }
    }

    var method: HTTPMethod {
        switch self {
        case .ticker, .transactionHistory, .candlestick:
            return .get
        }
    }

    // MARK: - Paths

    var path: String {
        switch self {
        case .ticker(let coinSymbol):
            return &quot;/ticker/\(coinSymbol)_KRW&quot;
        case .transactionHistory(let coinSymbol):
            return &quot;/transaction_history/\(coinSymbol)_KRW&quot;
        case .candlestick(let coinSymbol):
            return &quot;/candlestick/\(coinSymbol)_KRW&quot;
        }
    }

    // MARK: - asURLRequset

    func asURLRequest() -&gt; URLRequest {
        let url = baseURL.appendingPathComponent(path)
        var urlRequset = URLRequest(url: url)
        urlRequset.httpMethod = &quot;\(method)&quot;

        return urlRequset
    }
}
</code></pre>
<p>*<em>개선된 HTTPService *</em></p>
<pre><code class="language-swift">func request(_ router: APIRouter) -&gt; AnyPublisher&lt;Data, HTTPError&gt; 

// 사용 시 
// 비트코인 현재가를 조회하는 API
let bitcoinTicker = APIRouter.ticker(&quot;BTC&quot;)

request(bitcoinTicker)
    .sink {
       // ...
    }
</code></pre>
<p><code>APIRouter 열거형</code>에 <code>연산 프로퍼티(baseURL, method, path)</code>를 만들고, <code>Associated Values</code>으로 <code>CoinSymbol</code>을 넘겨준다.
<code>EndPoint</code>를 구성하는 요소들을 하나의 타입에 모아둘 수 있다.
또, <code>asURLRequset() -&gt; URLRequest</code> 메서드 내부에서 구성요소들로 URLRequest를 만든다.</p>
<h3 id="마무리">마무리</h3>
<p>이번 포스팅에서는 EndPoint 생성 및 개선했다.
위 포스팅처럼 하나의 <code>APIRouter</code>에서 여러 EndPoint를 관리하면 앱에서 사용하고 있는 EndPoint들을 한눈에 확인할 수 있는 장점이 있다.
하지만, EndPoint가 추가될수록 <code>APIRouter</code>가 비대해 질 수 있고, 기존 코드에 영향을 줄 수 있다고 판단된다.(단일책임 원칙, 개방폐쇄 원칙 위배....)</p>
<p>추후 EndPoint가 추가될 수 있는 점을 감안하면 구조는 다시 한번 개선해야겠다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[후회 - SwiftUI 전환기]]></title>
            <link>https://velog.io/@h_jeha/%ED%9B%84%ED%9A%8C-SwiftUI-%EC%A0%84%ED%99%98%EA%B8%B0</link>
            <guid>https://velog.io/@h_jeha/%ED%9B%84%ED%9A%8C-SwiftUI-%EC%A0%84%ED%99%98%EA%B8%B0</guid>
            <pubDate>Mon, 18 Jul 2022 06:23:20 GMT</pubDate>
            <description><![CDATA[<h1 id="후회---그-때-샀으면-지금-얼마일까">후회 - 그 때 샀으면 지금 얼마일까?</h1>
<blockquote>
<p>개발 인원 : iOS 2인
개발 시작 : 2022.04.06
출시 날짜 : 2022.05.22</p>
</blockquote>
<h3 id="앱-스토어-링크">앱 스토어 링크</h3>
<p><a href="https://apps.apple.com/kr/app/%ED%9B%84%ED%9A%8C-%EA%B7%B8-%EB%95%8C-%EC%83%80%EC%9C%BC%EB%A9%B4-%EC%A7%80%EA%B8%88-%EC%96%BC%EB%A7%88%EC%9D%BC%EA%B9%8C/id1624645983"><img src="https://i.imgur.com/kZiWHOT.png" width="100" height="100"></a></p>
<h3 id="uikit-rxswift에서-swiftui-combine으로">UIKit, RxSwift에서 SwiftUI, Combine으로</h3>
<p>기존 <code>UIKit</code>과 <code>RxSwift</code>로 구현되어 있는 프로젝트를 <code>SwiftUI</code>, <code>Combine</code>으로 다시 만드는 과정을 통해 <code>SwiftUI</code>, <code>Combine</code>을 공부할 수 있는 <code>*하준기</code>라 생각하고 그 과정을 기록할 예정이다.</p>
<p>얼마가 걸릴진 장담 못한다.</p>
<blockquote>
<p>*하준기 : 하늘이 준 기회</p>
</blockquote>
<h3 id="mvvm--cleanarchitecture에서-tcathe-composable-architecture로">MVVM + CleanArchitecture에서 TCA(The Composable Architecture)로</h3>
<p>후회를 만들면서 처음 MVVM을 공부했다. 
MVVM을 제대로 공부해야겠다는 마음가짐으로 CleanArchitecture를 도입했다.</p>
<h4 id="후회-architecture">후회 Architecture</h4>
<p><img src="https://velog.velcdn.com/images/h_jeha/post/d9c229e6-8a80-4138-9bd5-7490a6f9615c/image.png" alt="">
SwiftUI로 전환하는 과정도 마찬가지이다.
<a href="https://github.com/pointfreeco/swift-composable-architecture">TCA(The Composable Architecture)</a>를 도입해 볼 생각이다.</p>
<p>이것 또한 얼마가 걸릴진 장담 못한다.</p>
<p><a href="https://github.com/Team-Nogari/Huhoe">기존 프로젝트 Github</a></p>
<p><a href="https://github.com/Team-Nogari/Huhoe_SwiftUI">전환+ing 프로젝트 Github</a></p>
]]></description>
        </item>
    </channel>
</rss>