<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>주희하세요!</title>
    <description>caution Kim :: iOS Developer</description>
    <link>https://caution-dev.github.io/</link>
    <atom:link href="https://caution-dev.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 19 Sep 2021 10:19:01 +0000</pubDate>
    <lastBuildDate>Sun, 19 Sep 2021 10:19:01 +0000</lastBuildDate>
    <generator>Jekyll v3.9.0</generator>
    
      <item>
        <title>WKWebView &amp; Service Worker API</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#service-worker&quot; id=&quot;markdown-toc-service-worker&quot;&gt;Service Worker?&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#wkwebview&quot; id=&quot;markdown-toc-wkwebview&quot;&gt;WKWebView&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#default-browser&quot; id=&quot;markdown-toc-default-browser&quot;&gt;Default Browser&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

2018/2/7의 &lt;a href=&quot;https://webkit.org/blog/8090/workers-at-your-service/&quot;&gt;WebKit&lt;/a&gt;의 포스팅에 의하면 Safari와 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SFSafariViewController&lt;/code&gt;에서 &lt;a href=&quot;&quot;&gt;Service Worker API&lt;/a&gt;를 지원한다고 합니다.
11.3 부터 지원이 된 것 같은데 이 시점에는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WKWebView&lt;/code&gt; 에서 지원이 된 것은 아니었던 것으로..

&lt;h4 id=&quot;service-worker&quot;&gt;Service Worker?&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://w3c.github.io/ServiceWorker/&quot;&gt;w3c의 ServiceWorker&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API&quot;&gt;MDN&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Service Worker&lt;/code&gt;는 (가능한 경우) 기본적으로 웹 애플리케이션, 브라우저 및 네트워크 사이에 있는 프록시 서버 역할을 한다. 이는 그 무엇보다도 효과적인 오프라인 경험의 생성을 가능하게 하고, 네트워크 요청을 가로채서 네트워크가 이용 가능 여부에 따라 적절한 조치를 취하고, 서버에 있는 Asset을 업데이트하기 위한 것이다. 또한 푸시 알림과 백그라운드 동기화 API에 대한 액세스를 허용한다.
&lt;/blockquote&gt;

개인적으로 이해하기로는, JS 베이스로 브라우저와는 별도로 추가로 동작하는 일꾼을 하나 둡니다. 이 일꾼을 통해 초기에 로딩했던 컨텐츠들을 관리하고, 새로운 업데이트가 필요하다면 서버에 요청하고, 그렇지 않을 경우 기존 리소스들을 사용하여 오프라인 상황에서도 정상적으로 동작하도록 효율적인 웹앱을 만들 수 있습니다.
Service Worker를 이야기 하다 보면 &lt;a href=&quot;https://developer.mozilla.org/ko/docs/Web/Progressive_web_apps/Introduction&quot;&gt;PWA&lt;/a&gt; 개념이 나오는데, 연결된 링크를 확인해주세요.

&lt;h5 id=&quot;wkwebview&quot;&gt;WKWebView&lt;/h5&gt;
아무튼 이 Service Worker API를 iOS 13 이후에서는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WKWebView&lt;/code&gt;에서 지원한다고 하는데, 별도의 API가 지원되는 것은 아닌 것 같고, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;navigation.serviceWorker&lt;/code&gt;에 접근해서 사용하는 듯 합니다.

결론은, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.entitlements&lt;/code&gt; 파일에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;com.apple.developer.WebKit.ServiceWorkers&lt;/code&gt;를 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;로 지정하니까 되었습니다.

테스트 방법은 다음과 같습니다.
&lt;ul&gt;
  &lt;li&gt;콘솔에서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;navigation.serviceWorker&lt;/code&gt;가 실존하는지 체크하기&lt;/li&gt;
  &lt;li&gt;https://googlechrome.github.io/samples/service-worker/basic/ 를 접속하여 개발자 콘솔을 열고, live test 를 동작시켜 network 탭에서 servie worker가 생성되는지 확인하기.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;default-browser&quot;&gt;Default Browser&lt;/h4&gt;
사실 저 entitlements key가, &lt;a href=&quot;https://developer.apple.com/documentation/bundleresources/entitlements&quot;&gt;공식 문서&lt;/a&gt; 상으로는 없는 것 같은데 다들 어떻게 알아오시는 걸까요 대단.. 연관된 가장 &lt;a href=&quot;https://developer.apple.com/documentation/xcode/preparing-your-app-to-be-the-default-browser-or-email-client&quot;&gt;최신 문서&lt;/a&gt;를 따르자면 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;com.apple.developer.web-browser&lt;/code&gt;를 사용하여 기본 브라우저 허용을 받으면 Service Worker 를 WKWebView에서 사용할 수 있다고 합니다.
기본 브라우저로 설정되면서 자연스럽게 serviceWorker 항목이 true 로 지정되는 것일까용.
</description>
        <pubDate>Wed, 04 Aug 2021 07:59:06 +0000</pubDate>
        <link>https://caution-dev.github.io/webkit/2021/08/04/serviceWorker.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/webkit/2021/08/04/serviceWorker.html</guid>
        
        <category>WebKit</category>
        
        <category>WKWebView</category>
        
        
        <category>WebKit</category>
        
      </item>
    
      <item>
        <title>AutoClosure</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#autoclosure&quot; id=&quot;markdown-toc-autoclosure&quot;&gt;AutoClosure&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#참조&quot; id=&quot;markdown-toc-참조&quot;&gt;참조&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

안녕하세요! caution입니다.

우리가 무심코 사용했던 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true &amp;amp;&amp;amp; false&lt;/code&gt; 에서 사용되는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&amp;amp;&lt;/code&gt;에 대해 알아보려고 합니다.
이 함수가 어떻게 생겼는지 아시나요? 요렇게 생겼숩니다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;/// - Parameters:&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;///   - lhs: The left-hand side of the operation.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;///   - rhs: The right-hand side of the operation.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;lhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;rhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@autoclosure&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;rethrows&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

여기서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoclosure&lt;/code&gt;라는 키워드가 나오는데 뭔지 아시나요? 저는 몰라서 &amp;gt;&amp;lt; 찾아보기로 하였습니다.

&lt;h3 id=&quot;autoclosure&quot;&gt;AutoClosure&lt;/h3&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoclosure&lt;/code&gt;는 함수에 인수로 전달되는 표현식을 자동적으로 감싸주는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;를 말합니다. 이것은 어떤 인수도 필요하지 않고, 이 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt; 불렸을 때, 그것은 그 안에 있는 표현식의 값을 반환합니다. 이러한 구문상의 편의성은 함수의 파라미터로 명시적 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;를 사용하는 대신 주변의 중괄호를 생략하면서 일반적인 표현식을 작성할 수 있도록 합니다.

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoclosure&lt;/code&gt;를 흔히 호출하지만 이러한 기능을 구현하는 것은 일반적이지 않습니다. 예를 들어, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;assert(condition:message:file:line:)&lt;/code&gt; 함수는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;condition&lt;/code&gt; 및 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;message&lt;/code&gt; 매개 변수 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoclosure&lt;/code&gt;로 받습니다. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;condition&lt;/code&gt; 인수는 디버그 빌드에서만 수행되고 조건이 거짓인 경우에만 메시지 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;message&lt;/code&gt; 인수가 수행됩니다.

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoclosure&lt;/code&gt;를 사용하면 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;를 호출할 때까지 내부 코드가 실행되지 않도록 지연시킬 수 있습니다. 이러한 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Delaying evaluation&lt;/code&gt;은 코드 수행 시기를 제어할 수 있기 때문에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;side-effect&lt;/code&gt;가 있거나 계산 비용이 많이 드는 코드에 유용합니다. 아래 코드는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;가 수행을 지연시키는 방식을 보여줍니다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;customersInLine&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Chris&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Alex&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Ewa&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Barry&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Daniella&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customersInLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Prints &quot;5&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;customerProvider&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customersInLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customersInLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Prints &quot;5&quot;&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Now serving &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;customerProvider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Prints &quot;Now serving Chris!&quot;&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customersInLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Prints &quot;4&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;customersInLine&lt;/code&gt;의 첫 번째 요소는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt; 내부의 코드에 의해 제거되며, 배열의 요소는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;가 실제로 호출될 때까지 제거되지 않습니다. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;를 호출하지 않으면 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt; 내부의 식이 평가되지 않으며, 이는 배열 요소가 제거되지 않음을 의미합니다. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;customerProvider&lt;/code&gt;의 type은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;이 아니라 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;() -&amp;gt; String&lt;/code&gt;으로, 문자열을 반환하는 매개 변수가 없는 함수입니다.

함수에 매개 변수로 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;를 전달할 때에도 동일한 방식으로 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt; 수행을 지연시킬 수 있습니다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// customersInLine is [&quot;Alex&quot;, &quot;Ewa&quot;, &quot;Barry&quot;, &quot;Daniella&quot;]&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;serve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;customerProvider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Now serving &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;customerProvider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;serve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;customer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customersInLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Prints &quot;Now serving Alex!&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

위의 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;serve(고객:)&lt;/code&gt; 함수는 고객의 이름을 반환하는 명시적 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;를 인수로 받습니다. 아래 버전의 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;serve(고객:)&lt;/code&gt; 동일한 작업을 수행하지만 해당 매개 변수의 유형을 명시적 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;가 아닌 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@autoclosure&lt;/code&gt; 특성으로 표기하여 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoclosure&lt;/code&gt;를 받습니다. 이제 매개 변수로 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt; 대신 문자열을 사용한 것처럼 함수를 호출할 수 있습니다. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;customerProvider&lt;/code&gt; 매개 변수의 유형이 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@autoclosure&lt;/code&gt; 특성을 가지므로 인수가 자동으로 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;로 변환됩니다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// customersInLine is [&quot;Ewa&quot;, &quot;Barry&quot;, &quot;Daniella&quot;]&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;serve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;customerProvider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@autoclosure&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Now serving &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;customerProvider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;serve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;customer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customersInLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Prints &quot;Now serving Ewa!&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

scope 탈출 허용되는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoclosure&lt;/code&gt;를 원하는 경우 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@autoclosure&lt;/code&gt; 및 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@escaping&lt;/code&gt; 특성을 모두 사용하십시오. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@escaping&lt;/code&gt; 특성은 위의 &lt;a href=&quot;https://docs.swift.org/swift-book/LanguageGuide/Closures.html#ID546&quot;&gt;Escaping Closures&lt;/a&gt;를 참고하세요.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// customersInLine is [&quot;Barry&quot;, &quot;Daniella&quot;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;customerProviders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;collectCustomerProviders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;customerProvider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@autoclosure&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@escaping&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;customerProviders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customerProvider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;collectCustomerProviders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customersInLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;collectCustomerProviders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customersInLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Collected &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customerProviders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; closures.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Prints &quot;Collected 2 closures.&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerProvider&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerProviders&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Now serving &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;customerProvider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Prints &quot;Now serving Barry!&quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Prints &quot;Now serving Daniella!&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autoclosure&lt;/code&gt;

위의 코드에서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;collectCustomerProviders(_:)&lt;/code&gt; 기능은 전달된 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;customerProvider&lt;/code&gt; 인수 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;를 호출하는 대신 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;collectCustomerProviders&lt;/code&gt;에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;를 추가합니다. 배열은 함수의 범위 밖에 선언됩니다. 즉, 함수가 반환된 후 배열의 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closure&lt;/code&gt;를 실행할 수 있습니다. 따라서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;customerProvider&lt;/code&gt; 매개 변수의 값이 함수의 범위를 벗어날 수 있도록 허용되어야 합니다.

&lt;h3 id=&quot;참조&quot;&gt;참조&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.swift.org/swift-book/LanguageGuide/Closures.html&quot;&gt;Closures&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sun, 27 Jun 2021 07:05:06 +0000</pubDate>
        <link>https://caution-dev.github.io/swift/2021/06/27/autoClosure.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/swift/2021/06/27/autoClosure.html</guid>
        
        <category>Swift</category>
        
        <category>Closure</category>
        
        <category>번역</category>
        
        
        <category>Swift</category>
        
      </item>
    
      <item>
        <title>[SiriKit] INIntentHandlerProviding</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#protocol&quot; id=&quot;markdown-toc-protocol&quot;&gt;Protocol&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#inintenthandlerproviding&quot; id=&quot;markdown-toc-inintenthandlerproviding&quot;&gt;INIntentHandlerProviding&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#declaration&quot; id=&quot;markdown-toc-declaration&quot;&gt;Declaration&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#overview&quot; id=&quot;markdown-toc-overview&quot;&gt;Overview&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;protocol&quot;&gt;Protocol&lt;/h4&gt;
&lt;h2 id=&quot;inintenthandlerproviding&quot;&gt;INIntentHandlerProviding&lt;/h2&gt;
해당 intent들을 처리하는 커스텀 객체에 intent를 전달하기 위한 인터페이스

&lt;h3 id=&quot;declaration&quot;&gt;Declaration&lt;/h3&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;INIntentHandlerProviding&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;overview&quot;&gt;Overview&lt;/h3&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INIntentHandlerProviding&lt;/code&gt; 프로토콜은 SiriKit 요청을 Intents Extension의 적절한 객체로 라우팅하는 방법을 정의합니다. 이 프로토콜의 메소드는 특정 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Intent&lt;/code&gt; 객체를 해결/확인/처리가 가능한 객체를 반환하는 디스패처 역할을 합니다. 이 프로토콜은 &lt;a href=&quot;https://developer.apple.com/documentation/sirikit/inextension&quot;&gt;INExtension&lt;/a&gt; 클래스가 채택하고 있으며 사용자에 맞게 커스텀하여 제공해야 합니다.

프로젝트에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Intent&lt;/code&gt; extension을 추가하면, Xcode는 자동으로 이 프로토콜을 채택한 기본 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INExtension&lt;/code&gt; 하위클래스를 만듭니다. 이 하위클래스의 &lt;a href=&quot;https://developer.apple.com/documentation/sirikit/inintenthandlerproviding/1638898-handler&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hadler(for:)&lt;/code&gt;&lt;/a&gt; 메서드를 수정하여 처리 객체를 생서하도록 사용하세요. 여러 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Intent&lt;/code&gt;에 대해 같은 클래스를 사용하거나, 각 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Intent&lt;/code&gt;에 따라 다른 클래스를 사용해도 됩니다.

</description>
        <pubDate>Thu, 13 May 2021 12:42:06 +0000</pubDate>
        <link>https://caution-dev.github.io/apple-docs/2021/05/13/INIntentHandlerProviding.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/apple-docs/2021/05/13/INIntentHandlerProviding.html</guid>
        
        <category>iOS</category>
        
        <category>Swift</category>
        
        <category>Intent</category>
        
        <category>Extension</category>
        
        <category>SiriKit</category>
        
        
        <category>Apple-Docs</category>
        
      </item>
    
      <item>
        <title>[SiriKit] Resolving and Handling Intents</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#article&quot; id=&quot;markdown-toc-article&quot;&gt;Article&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#intent-해결-및-처리&quot; id=&quot;markdown-toc-intent-해결-및-처리&quot;&gt;Intent 해결 및 처리&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#overview&quot; id=&quot;markdown-toc-overview&quot;&gt;Overview&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#중요&quot; id=&quot;markdown-toc-중요&quot;&gt;중요&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#topics&quot; id=&quot;markdown-toc-topics&quot;&gt;Topics&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#resolving-and-handling-intents&quot; id=&quot;markdown-toc-resolving-and-handling-intents&quot;&gt;Resolving and Handling intents&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#intent를-이행하고-sirikit에게-당신이-한-일에-대한-피드백을-제공합니다&quot; id=&quot;markdown-toc-intent를-이행하고-sirikit에게-당신이-한-일에-대한-피드백을-제공합니다&quot;&gt;Intent를 이행하고 SiriKit에게 당신이 한 일에 대한 피드백을 제공합니다.&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#responses&quot; id=&quot;markdown-toc-responses&quot;&gt;Responses&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#함께-보기&quot; id=&quot;markdown-toc-함께-보기&quot;&gt;함께 보기&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#siri-intents&quot; id=&quot;markdown-toc-siri-intents&quot;&gt;Siri Intents&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

안녕하세요! caution입니다.

SiriKit을 써보고 싶었던 건 아니고, 단축어를 앱에 적용해보고 싶었는데 그게 SiriKit 내부에 포함되나 보더라고요 (맞나) 그래서 급작스런 SiriKit 입니다.

&lt;h4 id=&quot;article&quot;&gt;Article&lt;/h4&gt;
&lt;h2 id=&quot;intent-해결-및-처리&quot;&gt;Intent 해결 및 처리&lt;/h2&gt;
앱 서비를 위해 사용자의 요구사항을 resolve(해결하고), confirm(확정해주고), handle(다루기)

&lt;h3 id=&quot;overview&quot;&gt;Overview&lt;/h3&gt;
SiriKit은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Intents app extension&lt;/code&gt;과 함께 제공된 정보를 기반으로 사용자의 요청을 수행할 수 있는지 확인합니다. 해결 단계에서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;intent&lt;/code&gt; 객체의 개별 매개 변수(parameter)를 확인하고 필요에 따라 SiriKit에 설명을 요청합니다. 확인 단계에서 모든 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;intent&lt;/code&gt; 파라미터에 대한 마지막 점검을 한 번 수행하고, 서비스가 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;intent&lt;/code&gt;의 요구를 이행할 준비가 되었는지 확인합니다. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;intent&lt;/code&gt;가 유효하다면, SiriKit에서 해당 의도를 당신이(우리 앱이) 처리하도록 요청합니다.

&lt;blockquote&gt;
  &lt;h3 id=&quot;중요&quot;&gt;중요&lt;/h3&gt;
  watchOS는 모든 의도를 지원하지 않습니다. 예를 들어, watchOS의 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Intents App Extension&lt;/code&gt;은 비디오 통화를 시작하거나 메시지 속성을 설정하거나 CarPlay 도메인 관련 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;intent&lt;/code&gt;를 처리할 수 없습니다. watchOS에서 이들을 처리하기 전에 가능 여부를 먼저 확인하세요.
&lt;/blockquote&gt;

&lt;h2 id=&quot;topics&quot;&gt;Topics&lt;/h2&gt;
&lt;hr /&gt;
&lt;h4 id=&quot;resolving-and-handling-intents&quot;&gt;Resolving and Handling intents&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/resolving_and_handling_intents/resolving_the_parameters_of_an_intent&quot;&gt;Intent 해결 및 관리&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;Intent의 매개변수를 확인하고, 처리하기 위한 모든 정보가 있는지 확인합니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/resolving_and_handling_intents/confirming_the_details_of_an_intent&quot;&gt;Confirming the Details of an Intent&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;Intent의 매개변수를 최종 확인하고, 서비스가 이 Intent를 처리할 준비가 되었는지 확인합니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/resolving_and_handling_intents/handling_an_intent&quot;&gt;Handling an Intent&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;h2 id=&quot;intent를-이행하고-sirikit에게-당신이-한-일에-대한-피드백을-제공합니다&quot;&gt;Intent를 이행하고 SiriKit에게 당신이 한 일에 대한 피드백을 제공합니다.&lt;/h2&gt;
        &lt;h4 id=&quot;responses&quot;&gt;Responses&lt;/h4&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/inintentresolutionresult&quot;&gt;class INIntentResolutionResult&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;Intent 객체의 파라미터에 대한 해결 결과&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/inintentresponse&quot;&gt;class INIntentResponse&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;Intent 객체에 대한 당신의 응답&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;함께-보기&quot;&gt;함께 보기&lt;/h2&gt;
&lt;h4 id=&quot;siri-intents&quot;&gt;Siri Intents&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/creating_an_intents_app_extension&quot;&gt;Creating an Intents App Extension&lt;/a&gt;
Xcode project에 Intent app extension을 추가하고 설정해봅시다.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/structuring_your_code_to_support_app_extensions&quot;&gt;Structuring Your Code to Support App Extensions&lt;/a&gt;
백엔드 서비스를 프라이빗 프레임워크로 옮겨서 앱과 앱 익스텐션이 함께 사용할 수 있도록 해봅니다.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/dispatching_intents_to_handler_objects&quot;&gt;Dispatching Intents to Handler Objects&lt;/a&gt;
SiriKit에게 주어진 intent를 처리할 수 있는 객체를 제공합니다.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://caution-dev.github.io/swift/2021/05/13/INIntentHandlerProviding.html&quot;&gt;protocol INIntentHandlerProviding&lt;/a&gt;
해당 intent들을 처리하는 커스텀 객체에 intent를 전달하기 위한 인터페이스&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/intents_and_related_classes&quot;&gt;Intents and Related Classes&lt;/a&gt;
Inetent 익스텐션을 구성하기 위한 클래스를 배워봅시다.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/sirikit/providing_hands-free_app_control_with_intents&quot;&gt;Providing Hands-Free App Control with Intents&lt;/a&gt;
익스텐션 없이 intent를 해결하고 / 확정하고 / 처리해봅시다.&lt;/li&gt;
&lt;/ul&gt;

그럼 이만! 뿅!
</description>
        <pubDate>Thu, 13 May 2021 10:42:06 +0000</pubDate>
        <link>https://caution-dev.github.io/apple-docs/2021/05/13/Resolving_and_Handling_Intents.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/apple-docs/2021/05/13/Resolving_and_Handling_Intents.html</guid>
        
        <category>iOS</category>
        
        <category>Swift</category>
        
        <category>Intent</category>
        
        <category>Extension</category>
        
        <category>SiriKit</category>
        
        
        <category>Apple-Docs</category>
        
      </item>
    
      <item>
        <title>[ARC] Unowned vs Weak</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#unowned-optional-references-example&quot; id=&quot;markdown-toc-unowned-optional-references-example&quot;&gt;Unowned Optional References Example&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#참조&quot; id=&quot;markdown-toc-참조&quot;&gt;참조&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

안녕하세요! caution입니다.

Swift 5.0 부터 unowned 가 Optional Type이 가능해졌잖아요.
앗 그럼 weak랑 뭐가 많이 다른 거지.. 하고 간만에 ARC 문서를 읽어보았숩니다.
번역은 나중에하고 본론으로 :0

weak 와 unowned 모두 Reference Count를 증가시키지 않습니다.
weak의 경우 참조된 객체가 deinit 될 경우 ARC에 의해 nil 로 변경됩니다.
하지만 unowned는 deinit 되어도 ARC가 nil로 변경해주지 않습니다.
그래서 이미 해제된 객체에 접근하려고 하기 때문에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BAD ACCESS&lt;/code&gt; runtime error가 발생합니다.

unowned의 정의 자체는 동일한데, Type이 Optional 이 되었다는 것은 무엇이냐.
예전에는 weak와 unowned의 가장 큰 차이가 &lt;strong&gt;Optional인지 여부&lt;/strong&gt;였습니다. 하지만 이제 unowned도 &lt;strong&gt;Optional Type이 가능&lt;/strong&gt;해졌죠. 그 말은 의도적으로 nil 인 경우도 가능하다는 의미인데, 한국어가 어려우니 예시를 들어봅시다.

&lt;h3 id=&quot;unowned-optional-references-example&quot;&gt;Unowned Optional References Example&lt;/h3&gt;
대학교를 생각해봅시다. 각 학부는 정해진 전공 과목들이 있고, 각 과목에는 후행되는 과목 (DB1 -&amp;gt; DB2 -&amp;gt; DB 심화)이 &lt;strong&gt;있을 수 있습니다.&lt;/strong&gt; 물론 없을 수도 있죠.

이걸 다음과 같이 정의해봅시다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Department&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;courses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Course&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;courses&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Course&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;unowned&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Department&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;unowned&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;nextCourse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Course&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;department&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nextCourse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

하지만 이 과목들은 부서가 없다면 존재하지 않습니다. 공통 교양과목이 아니라 전공과목이라 생각해보자구요. 그래서 department는 course보다 &lt;strong&gt;길거나 같은&lt;/strong&gt; 생명주기를 따릅니다. 과목은 있거나 없어질 수 있지만, 전공 과목인데 전공 부서가 없는 건 이상하잖아요.

그래서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unowned&lt;/code&gt;로 정의해주었습니다.

마찬가지로 후행 과목도, DB1이 없는데 DB2 가 있는 건 이상하니까 후행 과목이 선행 과목보다 &lt;strong&gt;길거나 같은 생명주기&lt;/strong&gt;를 가진다고 생각합니다. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;department&lt;/code&gt;와 같이 동일 논리로 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unowned&lt;/code&gt;로 정의해주고 싶은데, 문제는 후행 학습이 있을 수도 있고, 없을 수도 있다는 거죠 :0 그래서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&amp;lt;Course&amp;gt;&lt;/code&gt;로 후행 학습의 타입을 결정해주었습니다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Horticulture&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;intro&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Course&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Survey of Plants&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;intermediate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Course&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Growing Common Herbs&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;advanced&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Course&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Caring for Tropical Plants&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;intro&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nextCourse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;intermediate&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;intermediate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nextCourse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;advanced&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;courses&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;intro&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;intermediate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;advanced&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

이런식으로 unowned relationship을 구성해줄 수 있습니다.
마지막 과목인 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;advanced&lt;/code&gt;는 후행 과목이 없기 때문에 셋해주지 않았습니다.

이들간의 관계도는 다음과 같습니다.

&lt;img src=&quot;https://docs.swift.org/swift-book/_images/unownedOptionalReference_2x.png&quot; alt=&quot;image&quot; /&gt;

이렇게 보면 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unowned&lt;/code&gt;가 Optional이 될 수 있는 것이 뭔가 당연한데, Swift 5 이전에는 이런 경우에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;weak&lt;/code&gt;를 썼던 걸까요? :0? 궁그미.. 누군가는 필요하다고 생각하니 추가되었겠지요.

사실 어떤 객체와 다른 객체의 관계에 대한 생명주기를 확신하기 어려워 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unowned&lt;/code&gt;는 잘 쓰지 않았었는데, 용기를 가지고 시도해봐야겠어요.

결국 weak와 unowned의 가장 큰 차이! 는 이제 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ARC&lt;/code&gt;에 의해 nil로 변경이 되냐 안 되냐의 차이만 남았네요.

오히려 더 clear~~ 해진 느낌 &amp;gt;&amp;lt;

그럼 이만 뿅!

&lt;h3 id=&quot;참조&quot;&gt;참조&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html&quot;&gt;ARC Summary&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sat, 10 Apr 2021 15:26:06 +0000</pubDate>
        <link>https://caution-dev.github.io/swift/2021/04/10/ARC.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/swift/2021/04/10/ARC.html</guid>
        
        <category>iOS</category>
        
        <category>면접준비</category>
        
        <category>strong</category>
        
        <category>weak</category>
        
        <category>Swift</category>
        
        
        <category>Swift</category>
        
      </item>
    
      <item>
        <title>Go Live with ReplayKit</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#replaykit&quot; id=&quot;markdown-toc-replaykit&quot;&gt;ReplayKit&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#새로운-기능&quot; id=&quot;markdown-toc-새로운-기능&quot;&gt;새로운 기능&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#replaykit-architecture&quot; id=&quot;markdown-toc-replaykit-architecture&quot;&gt;ReplayKit Architecture&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#class-and-protocols&quot; id=&quot;markdown-toc-class-and-protocols&quot;&gt;Class and Protocols&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#rpscreenrecorder&quot; id=&quot;markdown-toc-rpscreenrecorder&quot;&gt;RPScreenRecorder&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#rpscreenrecorderdelegate&quot; id=&quot;markdown-toc-rpscreenrecorderdelegate&quot;&gt;RPScreenRecorderDelegate&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#rppreviewviewcontroler&quot; id=&quot;markdown-toc-rppreviewviewcontroler&quot;&gt;RPPreviewViewControler&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#rppreviewcontrollerdelegate&quot; id=&quot;markdown-toc-rppreviewcontrollerdelegate&quot;&gt;RPPreviewControllerDelegate&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#replaykit-on-apple-tv&quot; id=&quot;markdown-toc-replaykit-on-apple-tv&quot;&gt;ReplayKit on Apple TV&lt;/a&gt;            &lt;ul&gt;
              &lt;li&gt;&lt;a href=&quot;#startrecording&quot; id=&quot;markdown-toc-startrecording&quot;&gt;StartRecording&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#discarding-the-recording&quot; id=&quot;markdown-toc-discarding-the-recording&quot;&gt;Discarding the Recording&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#replaykit-on-apple-tv-1&quot; id=&quot;markdown-toc-replaykit-on-apple-tv-1&quot;&gt;ReplayKit on Apple TV&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#live-broadcast&quot; id=&quot;markdown-toc-live-broadcast&quot;&gt;Live Broadcast&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#initiating-a-broadcast&quot; id=&quot;markdown-toc-initiating-a-broadcast&quot;&gt;Initiating a Broadcast&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#indicating-a-broadcast&quot; id=&quot;markdown-toc-indicating-a-broadcast&quot;&gt;Indicating a Broadcast&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#finish-broadcast&quot; id=&quot;markdown-toc-finish-broadcast&quot;&gt;Finish Broadcast&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#사용자가-앱을-백그라운드로-내린다거나-전화가-온다거나-하는-상황에선&quot; id=&quot;markdown-toc-사용자가-앱을-백그라운드로-내린다거나-전화가-온다거나-하는-상황에선&quot;&gt;사용자가 앱을 백그라운드로 내린다거나, 전화가 온다거나 하는 상황에선?&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#class와-protocol&quot; id=&quot;markdown-toc-class와-protocol&quot;&gt;Class와 Protocol&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#broadcast-services&quot; id=&quot;markdown-toc-broadcast-services&quot;&gt;Broadcast Services&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#broadcast-extensions&quot; id=&quot;markdown-toc-broadcast-extensions&quot;&gt;Broadcast Extensions&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#xcode-templates&quot; id=&quot;markdown-toc-xcode-templates&quot;&gt;Xcode Templates&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#broadcast-ui-extension&quot; id=&quot;markdown-toc-broadcast-ui-extension&quot;&gt;Broadcast UI Extension&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#broadcast-upload-extension&quot; id=&quot;markdown-toc-broadcast-upload-extension&quot;&gt;Broadcast Upload Extension&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#추가-옵션&quot; id=&quot;markdown-toc-추가-옵션&quot;&gt;추가 옵션&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2016/601/&quot;&gt;영상 링크&lt;/a&gt;

&lt;h2 id=&quot;replaykit&quot;&gt;ReplayKit&lt;/h2&gt;
ReplayKit을 사용하면, 사용자는 화면의 영상과 앱과 마이크의 오디오를 녹화할 수 있다.
이를 통해 게임에 대한 음성 해설을 제공할 수 있고, 시스템 공유 시트를 사용하여 공유할 수 있다.

ReplayKit은 HD급 비디오를 제공합니다.
&lt;ul&gt;
  &lt;li&gt;게임 성능에 거의 영향을 주지 않고 장치의 배터리에서 최소의 전력을 소비한다.
사생활 보호&lt;/li&gt;
  &lt;li&gt;녹화가 시작되기 전 사용자 프롬프트를 표시하여 사용자들이 게임 플레이을 녹화하기 전 인지하고 이를 허용한다.&lt;/li&gt;
  &lt;li&gt;시스템 UI는 제외하여 녹화한다. (메세지, 애플리케이션 알림 등)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;새로운-기능&quot;&gt;새로운 기능&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Apple TV OS에서 ReplayKit 지원&lt;/li&gt;
  &lt;li&gt;실시간으로 브로드캐스팅 가능 ( 타사 방송 서비스까지 지원 )&lt;/li&gt;
  &lt;li&gt;Face Time 카메라를 녹화할 수 있으며, 마이크 녹음 API를 향상시킴&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;replaykit-architecture&quot;&gt;ReplayKit Architecture&lt;/h3&gt;
&lt;img src=&quot;/images/replayKit/replaykit_wwdc_00.png&quot; alt=&quot;images&quot; /&gt;
애플리케이션에서 운영체제를 통해 레코딩을 시작하려면 RPScreenRecorder을 통해 녹화를 시작할 수 있다.
녹화가 시작되면 Replay Daemon 으로 메세지가 전달되고 앱의 데이터를 Movie file에 쓰기 시작한다.

&lt;img src=&quot;/images/replayKit/replaykit_wwdc_01.png&quot; alt=&quot;images&quot; /&gt;
애플리케이션이 녹화를 중지하면 Replay Daemon이 쓰기를 종료하고 완성된 Movie file을 Application 단으로 돌려주기 위해 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RPPreviewViewController&lt;/code&gt;를 제공한다.
이 뷰 컨트롤러를 통해 사용자들은 영상을 미리 보면서 편집하고, 공유할 수 있다.

&lt;h3 id=&quot;class-and-protocols&quot;&gt;Class and Protocols&lt;/h3&gt;
&lt;h4 id=&quot;rpscreenrecorder&quot;&gt;RPScreenRecorder&lt;/h4&gt;
녹화를 시작 / 중단 / 취소
현재 녹화할 수 있는지 체크할 수 있음

&lt;h4 id=&quot;rpscreenrecorderdelegate&quot;&gt;RPScreenRecorderDelegate&lt;/h4&gt;
녹화 가능 여부가 변경되는 시점을 알 수 있음
오류가 발생하여 녹화가 중지되었을 때를 알 수 있음

&lt;h4 id=&quot;rppreviewviewcontroler&quot;&gt;RPPreviewViewControler&lt;/h4&gt;
사용자에게 녹화영상을 미리볼 수 있는 뷰 컨트롤러를 제공
편집과 잘라내기, 공유

&lt;h4 id=&quot;rppreviewcontrollerdelegate&quot;&gt;RPPreviewControllerDelegate&lt;/h4&gt;
프리뷰가 종료되었을 때의 시점을 알 수 있다.

&lt;h4 id=&quot;replaykit-on-apple-tv&quot;&gt;ReplayKit on Apple TV&lt;/h4&gt;
&lt;h5 id=&quot;startrecording&quot;&gt;StartRecording&lt;/h5&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;lazy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;sharedRecorder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPScreenRecorder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;shared&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;didPressRecordButton&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sharedRecorder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;startRecording&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;              &lt;span class=&quot;c1&quot;&gt;// 녹화 시작&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
           &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;showIndicatorView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Recording&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 녹화중이라는 인디케이터를 보여줍시다.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;showIndicatorView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;recordingIndicatorWindow&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UIWindoe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;frame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UIScreen&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 별도 윈도우에 만들어서 영상에 포함되지 않음 ㅇㅁㅇ?&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;recordingIndicatorWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isHidden&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;recordingIndicatorWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;backgroundColor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UIColor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;clear&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;recordingIndicatorWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isUserInteractionEnabled&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;indicatorView&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;IndicatorView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;recordingIndicatorWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addSubview&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;indicatorView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 중지 버튼을 눌렀습니다!&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;didPressStopButton&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sharedRecorder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stopRecording&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previewViewController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// 녹화가 종료되면 previewViewController 객체가 함께 넘어옴&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;hideIndicatorView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

       &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// error 없이 종료되었다면 프리뷰 화면을 보여줄 것.&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;previewController&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previewViewController&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;previewViewController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;previewControllerDelegate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 메뉴가 뜬 상태에서, 공유를 눌렀을 경우&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;didPressShareButton&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;preview&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;previewViewController&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;preview&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;share&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;/// 미리보기는 preview&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;present&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;preview&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;animated&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 사용자가 프리뷰 화면에서 되돌아 오려고 할떄&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// RPPreviewViewControllerDelegate 내부 함수입니다.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;previewControllerDidFinish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;previewController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPPreviewViewController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;previewController&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dismiss&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;animated&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 옹 이쪽에서 닫아줍니다&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;discarding-the-recording&quot;&gt;Discarding the Recording&lt;/h3&gt;
다음 녹화가 시작되면 이전 녹화영상은 제거된다.
&lt;ul&gt;
  &lt;li&gt;하나의 앱에서는 하나의 녹화만 허용됨
PreviewController에 날라가면 같이 제거됨.&lt;/li&gt;
  &lt;li&gt;명시적으로 제거하고 싶다면 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RPScreenRecorder.discardRecording()&lt;/code&gt;을 사용할 것&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;replaykit-on-apple-tv-1&quot;&gt;ReplayKit on Apple TV&lt;/h2&gt;
비디오와 오디오 컨텐츠를 녹화할 수 있다.
&lt;ul&gt;
  &lt;li&gt;마이크는 시스템에 설정된 마이크를 사용합니다.
미리보기, 공유, 녹화, iOS와 같이 심플한 API, tvOS 10부터 사용가능쓰!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;live-broadcast&quot;&gt;Live Broadcast&lt;/h2&gt;
플레이어는 직접 iOS 또는 TVOS 장치에서 타사 스트리밍 서비스에 게임 플레이를 생방송할 수 있다.
iOS에서는 마이크와 카메라를 제공하여 FaceTime 카메라를 사용해 해설을 제공할 수도 있다.
컨텐츠는 broadcast service를 통해서만 접근 가능하며 매우매우 안전하다.

&lt;img src=&quot;/images/replayKit/replaykit_wwdc_02.png&quot; alt=&quot;images&quot; /&gt;

&lt;h3 id=&quot;initiating-a-broadcast&quot;&gt;Initiating a Broadcast&lt;/h3&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;didPressBroadcastButton&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kt&quot;&gt;RPBroadcastActivityViewController&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;broadcastAVC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// broadcast service 를 제공하는 앱을 선택할 수 있는 화면 표출해주기 (share extension이랑 비슷한 흐름)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;broadcastAVC&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;broadcastAVC&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;broadcastAVC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delegate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;present&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;broadcastAVC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;animated&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 서비스를 선택하고 / 혹은 선택하지 않고 닫았을 때&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// RPBroadcastActivityViewControllerDelegate&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;broadcastActivityViewController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;broadcastAVC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPBroadcastActivityViewController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;didFinishWith&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPBroadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

   &lt;span class=&quot;n&quot;&gt;broadcastAVC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dismiss&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;animated&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;startCountDownTimer&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;// 아니 broadcastController 이게 있는지 먼저 체크해야하는 거 아닌가&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;startBroadcast&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// broadcast started!&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;indicating-a-broadcast&quot;&gt;Indicating a Broadcast&lt;/h3&gt;
사용자에게 현재 broadcasting 중이라는 것을 알려주는 것이 중요함 ;)
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;broadcastController?.isBroadcasting&lt;/code&gt; 플래그를 사용할 것&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;finish-broadcast&quot;&gt;Finish Broadcast&lt;/h3&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;didPressBroadcastButton&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;finishBroadcast&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
             &lt;span class=&quot;c1&quot;&gt;// broadcast finished!&lt;/span&gt;
             &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;updateBroadcastUI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// RPBroadcastActivityViewControllerDelegate&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;broadcastActivityViewController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;broadcastActivityViewController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPBroadcastActivityViewController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;didFinishWith&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPBroadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?,&lt;/span&gt;
   &lt;span class=&quot;nv&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

     &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;broadcastController&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;broadcastController&lt;/span&gt;

     &lt;span class=&quot;c1&quot;&gt;// set a delegate to be notified of errors&lt;/span&gt;
     &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delegate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//RPBroadcastControllerDelegate&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPBroadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;didFinishWithError&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;c1&quot;&gt;// error occurred during broadcast&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;showErrorMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;localizedDescription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

      &lt;span class=&quot;c1&quot;&gt;// update UI to indicate the broadcast is stopped&lt;/span&gt;
     &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;updateBroadcastUI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;사용자가-앱을-백그라운드로-내린다거나-전화가-온다거나-하는-상황에선&quot;&gt;사용자가 앱을 백그라운드로 내린다거나, 전화가 온다거나 하는 상황에선?&lt;/h4&gt;
앱이 백그라운드에서 실행되면 브로드캐스트를 자동으로 일시 중단한다.
따라서 다시 활성화되는 시점에 사용자에게 브로드캐스트를 다시 재개할 것인지 물어봐야 한다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;applicationWillResignActive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// ReplayKit will automatically pause the broadcast&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

 &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;applicationDidBecomeActive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isBroadcasting&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;promptUserToResumeBroadcast&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;userWantsToResume&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
           &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userWantsToResume&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                  &lt;span class=&quot;c1&quot;&gt;// user wants to resume&lt;/span&gt;
                  &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;resumeBroadcast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
                  &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;updateBroadcastUI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                 &lt;span class=&quot;c1&quot;&gt;// user does not want to resume&lt;/span&gt;
                 &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;broadcastController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;finishBroadcast&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
                 &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;updateBroadcastUI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;class와-protocol&quot;&gt;Class와 Protocol&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;&quot;&gt;RPBroadcastActivityViewController&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;설치되어 있는 브로드캐스트 서비스들을 보여주는 칭구&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;&quot;&gt;RPBroadcastActivityViewControllerDelegate&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트 셋업이 완료되었을 때 알려줄 수 있는 delegate&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;&quot;&gt;RPBroadcastController&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트를 시작 / 종료 하는 주체&lt;/li&gt;
      &lt;li&gt;브로드캐스트가 현재 진행중인지 체크할 수 있음&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;&quot;&gt;RPBroadcastControllerDelegate&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트 중 나타나는 오류 핸들링&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;broadcast-services&quot;&gt;Broadcast Services&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Broadcast UI Extension
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트 시 나타나는 화면 설정&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Broadcast Upload Extension
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트 영상 / 음성 데이터 업로드 및 처리&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;broadcast-extensions&quot;&gt;Broadcast Extensions&lt;/h3&gt;
앱 내부에 포함되어 있지만, 다른 애플리케이션 process 에서 실행됨.
상위 애플리케이션과 데이터를 공유할 수 있음
애플리케이션에 비해서는 주어진 리소스가 제한적이다. (효율적이게 구성합시다)

&lt;h4 id=&quot;xcode-templates&quot;&gt;Xcode Templates&lt;/h4&gt;
Add Target -&amp;gt; iOS/tvOS -&amp;gt; Application Extension -&amp;gt; Broadcast UI Extension / Broadcast Upload Extension

&lt;h4 id=&quot;broadcast-ui-extension&quot;&gt;Broadcast UI Extension&lt;/h4&gt;
로그인이나 정보 등록 등 방송에 필요한 모든 전처리 단계가 이 단계에서 해야함.
이용약관을 보여주거나 이 영상을 외부 SNS 에 공유할 수 있는 등 !
셋업이 완료되면 브로드캐스트 설정이 완료되었음을 알려주어야 한다.

&lt;h4 id=&quot;broadcast-upload-extension&quot;&gt;Broadcast Upload Extension&lt;/h4&gt;
영상 / 음성 데이터를 받아서 처리
서버에 업로드
브로드 캐스트 서비스와 연관된 다른 필요한 요소들을 구현할 것.

&lt;img src=&quot;/images/replayKit/replaykit_wwdc_03.png&quot; alt=&quot;images&quot; /&gt;

&lt;h4 id=&quot;추가-옵션&quot;&gt;추가 옵션&lt;/h4&gt;
FaceTime camera 지원
&lt;ul&gt;
  &lt;li&gt;카메라 프리뷰를 제공
    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;cameraPreview&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPScreenRecorder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;shared&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cameraPreviewView&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;cameraPreview&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;frame&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CGRect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;…&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;view&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addSubview&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cameraPreview&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

유연한 마이크 녹음 지원
&lt;ul&gt;
  &lt;li&gt;켜고 끄는 방식! 초 심플!
    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;enableMic&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;kt&quot;&gt;RPScreenRecorder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;shared&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isMicrophoneEnabled&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;disableMic&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;kt&quot;&gt;RPScreenRecorder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;shared&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isMicrophoneEnabled&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

iOS 10 이상에서 사용 가능~
</description>
        <pubDate>Fri, 26 Mar 2021 08:26:16 +0000</pubDate>
        <link>https://caution-dev.github.io/swift/2021/03/26/ReplayKitWWDC.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/swift/2021/03/26/ReplayKitWWDC.html</guid>
        
        <category>iOS</category>
        
        <category>ReplayKit</category>
        
        <category>Swift</category>
        
        <category>Apple</category>
        
        <category>WWDC</category>
        
        
        <category>Swift</category>
        
      </item>
    
      <item>
        <title>RPBroadcastSampleHandler</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#class&quot; id=&quot;markdown-toc-class&quot;&gt;Class&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#rpbroadcastsamplehandler&quot; id=&quot;markdown-toc-rpbroadcastsamplehandler&quot;&gt;RPBroadcastSampleHandler&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#declaration&quot; id=&quot;markdown-toc-declaration&quot;&gt;Declaration&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#overview&quot; id=&quot;markdown-toc-overview&quot;&gt;Overview&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#sample-buffer-clips-처리하기&quot; id=&quot;markdown-toc-sample-buffer-clips-처리하기&quot;&gt;Sample Buffer Clips 처리하기&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#relationships&quot; id=&quot;markdown-toc-relationships&quot;&gt;RelationShips&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#inherits-from&quot; id=&quot;markdown-toc-inherits-from&quot;&gt;Inherits From&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#see-also&quot; id=&quot;markdown-toc-see-also&quot;&gt;See Also&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#media-clip-processing&quot; id=&quot;markdown-toc-media-clip-processing&quot;&gt;Media Clip Processing&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;class&quot;&gt;Class&lt;/h4&gt;
&lt;h2 id=&quot;rpbroadcastsamplehandler&quot;&gt;RPBroadcastSampleHandler&lt;/h2&gt;
ReplayKit에서 수신된 버퍼 개체를 처리하는 개체입니다.

&lt;h3 id=&quot;declaration&quot;&gt;Declaration&lt;/h3&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPBroadcastSampleHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RPBroadcastHandler&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;overview&quot;&gt;Overview&lt;/h3&gt;
ReplayKit에 의해 녹화되는 &lt;a href=&quot;https://developer.apple.com/documentation/coremedia/cmsamplebuffer&quot;&gt;CMSampleBuffer&lt;/a&gt;를 처리하기 위해서는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RPBroadcastSampleHandler&lt;/code&gt;를 서브클래싱하여 사용해야 합니다. 확장자의 Info.plist 파일에서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RPBroadcastProcessModeSampleBuffer&lt;/code&gt;를 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RPBroadcastProcessModeSampleBuffer&lt;/code&gt;로 설정하여 이 처리 모드를 활성화합니다.

하위 클래스에서 비디오 및 오디오 버퍼를 처리하는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;processSampleBuffer(_:with:)&lt;/code&gt; 메서드와 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;broadcastStarted(SetupInfo: )&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;broadcastFinished()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;broadcastPaused()&lt;/code&gt;, 그리고 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;broadcastResumed()&lt;/code&gt; 메서드를 구현하여 브로드캐스트 시작 및 중지를 처리합니다.

ReplayKit는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RPBroadcastSampleHandler&lt;/code&gt; 하위 클래스에서 메소드를 직렬 방식으로 호출합니다. 한 메서드를 호출한 후 ReplayKit은 첫 번째 메서드가 반환될 때까지 다른 메서드를 호출하지 않습니다. 즉, 스레드의 안전을 위해 잠금이나 동기화를 사용하지 않고도 저장된 상태를 업데이트할 수 있습니다.

&lt;h4 id=&quot;sample-buffer-clips-처리하기&quot;&gt;Sample Buffer Clips 처리하기&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastsamplehandler/2143170-broadcaststarted&quot;&gt;func broadcastStarted(withSetupInfo: [String: NSObject]?&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;라이브 브로드캐스트를 시작한 후 필요한 작업을 수행합니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastsamplehandler/2143174-broadcastpaused&quot;&gt;func broadcastPaused()&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;라이브 브로드캐스트가 중단된 후 필요한 작업을 수행합니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastsamplehandler/2143168-broadcastresumed&quot;&gt;func broadcastResumed()&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;라이브 브로드캐스트가 재시작된 후 필요한 작업을 수행합니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastsamplehandler/2143169-broadcastfinished&quot;&gt;func broadcastFinished()&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;라이브 브로드캐스트가 종료된 후 필요한 작업을 수행합니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastsamplehandler/2935571-broadcastannotated&quot;&gt;func broadcastAnnotated(withApplicationInfo: [AnyHashable: Any])&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;라이브 브로드캐스트를 시작한 후 필요한 작업을 수행합니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpapplicationinfobundleidentifierkey&quot;&gt;let RPApplicationInfoBundleIdentifierKey: String&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;사용자 정보 dictionary에서 앱의 번들 식별자를 검색하기 위한 키입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastsamplehandler/2123045-processsamplebuffer&quot;&gt;func processSampleBuffer(CMSampleBuffer, with: RPSampleBufferType)&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;라이브 방송 중에 비디오 및 오디오 데이터를 사용할 수 있게 되면 처리합니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpvideosampleorientationkey&quot;&gt;let RPVideoSampleOrientationKey: String&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;비디오 방향을 설명하는 샘플에 첨부된 키입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastsamplehandler/2721526-finishbroadcastwitherror&quot;&gt;func finishBroadcastWithError(Error)&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트를 중지하고 오류를 다시 브로드캐스트 앱으로 전달합니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;relationships&quot;&gt;RelationShips&lt;/h3&gt;
&lt;h4 id=&quot;inherits-from&quot;&gt;Inherits From&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcasthandler&quot;&gt;RPBroadcastHandler&lt;/a&gt;
    &lt;h3 id=&quot;see-also&quot;&gt;See Also&lt;/h3&gt;
    &lt;h4 id=&quot;media-clip-processing&quot;&gt;Media Clip Processing&lt;/h4&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastcontroller&quot;&gt;class RPBroadcastController&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트를 시작하고 제어하는 메서드를 포함하는 개체입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcasthandler&quot;&gt;class RPBroadcastHandler&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트 앱으로 메시지를 보내는 개체입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Fri, 26 Mar 2021 05:26:06 +0000</pubDate>
        <link>https://caution-dev.github.io/swift/2021/03/26/RPBroadcastSampleHandler.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/swift/2021/03/26/RPBroadcastSampleHandler.html</guid>
        
        <category>iOS</category>
        
        <category>ReplayKit</category>
        
        <category>Swift</category>
        
        <category>Apple</category>
        
        <category>WWDC</category>
        
        
        <category>Swift</category>
        
      </item>
    
      <item>
        <title>ReplayKit</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#framework&quot; id=&quot;markdown-toc-framework&quot;&gt;Framework&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#replaykit&quot; id=&quot;markdown-toc-replaykit&quot;&gt;ReplayKit&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#overview&quot; id=&quot;markdown-toc-overview&quot;&gt;Overview&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#주제&quot; id=&quot;markdown-toc-주제&quot;&gt;주제&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#replay-공유&quot; id=&quot;markdown-toc-replay-공유&quot;&gt;Replay 공유&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#media-clip-처리&quot; id=&quot;markdown-toc-media-clip-처리&quot;&gt;Media Clip 처리&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#live-broadcast-구현&quot; id=&quot;markdown-toc-live-broadcast-구현&quot;&gt;Live Broadcast 구현&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#error&quot; id=&quot;markdown-toc-error&quot;&gt;Error&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

안녕하세요! caution입니다. 회사에서 웨일온 만들면서 ReplayKit을 쓰게 되어가지고….
간만의 문서 번역이네용 :)

&lt;h4 id=&quot;framework&quot;&gt;Framework&lt;/h4&gt;
&lt;h2 id=&quot;replaykit&quot;&gt;ReplayKit&lt;/h2&gt;
화면의 비디오를, 앱과 마이크의 오디오를 가지고 비디오를 녹화하거나 스트리밍 합니다.

&lt;h3 id=&quot;overview&quot;&gt;Overview&lt;/h3&gt;
ReplayKit을 사용하면, 사용자는 화면의 영상과 앱과 마이크의 오디오를 녹화할 수 있습니다. 그리고 이는 메일, 메세지, 소셜미디어를 통해 다른 사용자들에게 고유할 수 있습니다. 콘텐츠를 공유 서비스로 실시간 브로드캐스트하기 위한 앱 확장을 구축할 수 있습니다. ReplayKit은 AVPlayer 컨텐츠와 호환되지 않습니다.

&lt;h3 id=&quot;주제&quot;&gt;주제&lt;/h3&gt;
&lt;h4 id=&quot;replay-공유&quot;&gt;Replay 공유&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/recording_and_streaming_your_macos_app&quot;&gt;macOS App 녹화하고 스트리밍하기&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;macOS 앱과 게임에 ReplayKit을 더함으로써 화면 녹화를 공유하거나 앱에서 실시간 음성 혹은 비디오를 브로드캐스트할 수 있습니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpscreenrecorder&quot;&gt;RPScreenRecoder&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;앱의 오디오 및 비디오를 녹화할 수 있는 공유 레코더 개체입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rppreviewviewcontroller&quot;&gt;RPPreviewViewController&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;사용자가 ReplayKit로 만든 화면 기록을 미리 보고 편집할 수 있는 사용자 인터페이스를 표시하는 개체입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;media-clip-처리&quot;&gt;Media Clip 처리&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastcontroller&quot;&gt;RPBroadcastController&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트 시작 및 제어 방법을 포함하는 개체&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcasthandler&quot;&gt;RPBroadcastHandler&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트 앱으로 메시지를 보내는 개체입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastsamplehandler&quot;&gt;RPBroadcastSampleHandler&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;ReplayKit에서 수신된 버퍼 개체를 처리하는 개체입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;live-broadcast-구현&quot;&gt;Live Broadcast 구현&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastactivityviewcontroller&quot;&gt;RPBroadcastActivityViewController&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;사용자가 브로드캐스트 서비스를 선택하는 사용자 인터페이스를 표시하는 뷰 컨트롤러입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpsystembroadcastpickerview&quot;&gt;RPSystemBroadcastPickerView&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;누르면 브로드캐스트 선택기가 표시되는 브로드캐스트 단추를 표시하는 뷰입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastactivitycontroller&quot;&gt;RPBroadcastActivityController&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;macOS 브로드캐스트 선택기를 표시하는 컨트롤러 객체입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rpbroadcastactivitycontrollerdelegate&quot;&gt;RPBroadcastActivityControllerDelegate&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;브로드캐스트 작업 제어기의 선택 이벤트에 응답하기 위해 구현할 방법을 정의하는 프로토콜입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;error&quot;&gt;Error&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rprecordingerrorcode&quot;&gt;RPRecordingErrorCode&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;ReplayKit 에러 도메인 코드들입니다.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/replaykit/rprecordingerrordomain-5gi&quot;&gt;RPRecodingErrorDomain&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;ReplayKit 프레임워크 오류 도메인.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Fri, 26 Mar 2021 04:26:06 +0000</pubDate>
        <link>https://caution-dev.github.io/swift/2021/03/26/ReplayKit.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/swift/2021/03/26/ReplayKit.html</guid>
        
        <category>iOS</category>
        
        <category>ReplayKit</category>
        
        <category>Swift</category>
        
        <category>Apple</category>
        
        
        <category>Swift</category>
        
      </item>
    
      <item>
        <title>SwiftUI Data Flow</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#9-data-flow&quot; id=&quot;markdown-toc-9-data-flow&quot;&gt;9. Data Flow&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#뭘-배울까요&quot; id=&quot;markdown-toc-뭘-배울까요&quot;&gt;뭘 배울까요?&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#property-wrappers&quot; id=&quot;markdown-toc-property-wrappers&quot;&gt;Property Wrappers&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#예를-들면&quot; id=&quot;markdown-toc-예를-들면&quot;&gt;예를 들면…&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#syntatic-sugar&quot; id=&quot;markdown-toc-syntatic-sugar&quot;&gt;Syntatic Sugar&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#왜-이런걸-만들어-둔-거야&quot; id=&quot;markdown-toc-왜-이런걸-만들어-둔-거야&quot;&gt;왜 이런걸 만들어 둔 거야?&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#published&quot; id=&quot;markdown-toc-published&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Published&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#state&quot; id=&quot;markdown-toc-state&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@State&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#observedobject&quot; id=&quot;markdown-toc-observedobject&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@ObservedObject&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#binding&quot; id=&quot;markdown-toc-binding&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Binding&lt;/code&gt;&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#상수값을-binding하기&quot; id=&quot;markdown-toc-상수값을-binding하기&quot;&gt;상수값을 Binding하기&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#computed-binding&quot; id=&quot;markdown-toc-computed-binding&quot;&gt;Computed Binding&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#environmentobject&quot; id=&quot;markdown-toc-environmentobject&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@EnvironmentObject&lt;/code&gt;&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#observedobject-1&quot; id=&quot;markdown-toc-observedobject-1&quot;&gt;ObservedObject&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#environmentobject-1&quot; id=&quot;markdown-toc-environmentobject-1&quot;&gt;EnvironmentObject&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#environment&quot; id=&quot;markdown-toc-environment&quot;&gt;Environment&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#custom-environment&quot; id=&quot;markdown-toc-custom-environment&quot;&gt;Custom Environment&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#publisher-맛보기&quot; id=&quot;markdown-toc-publisher-맛보기&quot;&gt;Publisher 맛보기&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#publisher&quot; id=&quot;markdown-toc-publisher&quot;&gt;Publisher?&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#listening-publisher&quot; id=&quot;markdown-toc-listening-publisher&quot;&gt;Listening Publisher&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#publishersinkreceivecompletion-receivevalue&quot; id=&quot;markdown-toc-publishersinkreceivecompletion-receivevalue&quot;&gt;Publisher.sink(receiveCompletion:, receiveValue:)&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#viewonreceivepublisher-perform&quot; id=&quot;markdown-toc-viewonreceivepublisher-perform&quot;&gt;View.onReceive(publisher:, perform:)&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#어디서-사용되나요&quot; id=&quot;markdown-toc-어디서-사용되나요&quot;&gt;어디서 사용되나요?&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#urlsessiondatataskpublisher&quot; id=&quot;markdown-toc-urlsessiondatataskpublisher&quot;&gt;URLSession.dataTaskPublisher&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#참조&quot; id=&quot;markdown-toc-참조&quot;&gt;참조&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;9-data-flow&quot;&gt;9. Data Flow&lt;/h1&gt;

&lt;h3 id=&quot;뭘-배울까요&quot;&gt;뭘 배울까요?&lt;/h3&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Property Wrappers&lt;/strong&gt; : @State @Published @ObservedObject&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Publishers&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;@Binding&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;property-wrappers&quot;&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0258-property-wrappers.md&quot;&gt;Property Wrappers&lt;/a&gt;&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Something&lt;/code&gt; 은 모두 Property Wrapper!&lt;/li&gt;
  &lt;li&gt;일반적으로 wrappedValue 와 projectedValue를 가지고 있는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;struct&lt;/code&gt; 임. 더 많은 property를 가질 수 도 있고, projectedValue가 없을 수도 있음!&lt;/li&gt;
  &lt;li&gt;이미 “&lt;strong&gt;정해져 있는 동작”&lt;/strong&gt; 들을 래핑하는 변수에 적용하여 캡슐화 함.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;예를-들면&quot;&gt;예를 들면…&lt;/h3&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@State&lt;/code&gt; :: View 내부에서 수정할 수 있도록 heap에 사는 변수 만들기

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Published&lt;/code&gt; :: 변수의 변경사항을 공표(publish)하기

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@ObservedObject&lt;/code&gt; :: publish된 변경사항이 감지되면 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;View&lt;/code&gt; 를 다시 그리도록 하기

&lt;h2 id=&quot;syntatic-sugar&quot;&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Syntactic_sugar&quot;&gt;Syntatic Sugar&lt;/a&gt;&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;@Published 는 사실 요렇게 생겼습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Published&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;initialValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;wrappedValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;projectedValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Publisher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Never&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// 우리가 $ 사용해서 연결할 때 여기 접근함&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;이렇게 선언하면&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;@Published&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;emojiArt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;EmojiArt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;EmojiArt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;사실 요렇게 쓰이는 거죠&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;_emojiArt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Published&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;EmojiArt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Published&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;wrappedValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;EmojiArt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;emojiArt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;EmojiArt&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_emojiArt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wrappedValue&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_emojiArt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wrappedValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newValue&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;왜-이런걸-만들어-둔-거야&quot;&gt;왜 이런걸 만들어 둔 거야?&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SwiftUI&lt;/code&gt; 를 사용하면서 필요한 주요 동작들이 있는데, 이를 템플릿화하여 사용자들이 잘~ 편하게~ 가져다 쓸 수 있도록 하기 위해서&lt;/li&gt;
  &lt;li&gt;각 Property Wrapper들은, 미리 “정해져있는” 동작을 하도록 선언되어 있습니다.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;published&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Published&lt;/code&gt;&lt;/h2&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrappedValue&lt;/code&gt; 가 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set&lt;/code&gt; 되는 시점에 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Publish&lt;/code&gt; ( &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;projectedValue&lt;/code&gt; )를 통해 변경사항을 전달한다. 이 변경사항은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$emojiArt&lt;/code&gt; 로 연결되어 있는 곳으로 전파됩니다. 그리고 이는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ObservableObject&lt;/code&gt; 에서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;objectWillChange.send()&lt;/code&gt; 를 호출합니다.

&lt;h2 id=&quot;state&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@State&lt;/code&gt;&lt;/h2&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrappedValue&lt;/code&gt; 가 값타입이건 참조타입이건(보통 스유에서는 값타입) heap에 저장합니다. 변경사항이 생기면, 연결된 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;View&lt;/code&gt; 를 다시 그립니다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;State&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DynamicProperty&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;initialValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;wrappedValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;projectedValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Binding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;   

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;DynamicProperty&lt;/strong&gt; :: View의 외부 속성을 업데이트하는 stored variable에 대한 interface&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://forums.swift.org/t/swiftui-state-init-wrappedvalue-vs-init-initialvalue-whats-the-difference/38904/19&quot;&gt;.init(wrappedValue:) vs .init(initialValue:)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;observedobject&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@ObservedObject&lt;/code&gt;&lt;/h2&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrappedValue&lt;/code&gt; 는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ObservableObject&lt;/code&gt; 를 채택한 타입이여야 합니다.

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrappedValue&lt;/code&gt; 가 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;objectWillChange.send()&lt;/code&gt; 를 호출했을 때 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;View&lt;/code&gt; 를 다시 그립니다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ObservedObject&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;ObjectType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DynamicProperty&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ObjectType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ObservableObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;initialValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;wrappedValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;projectedValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ObservedObject&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;ObjectType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Wrapper&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Wrapper&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;subscript&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Subject&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dynamicMember&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;keyPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ReferenceWritableKeyPath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;ObjectType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Subject&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Binding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Subject&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;binding&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Binding&lt;/code&gt;&lt;/h2&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrappedValue&lt;/code&gt; :: 다른 무언가와 연결된 값

다른 어떤 곳에서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wrappedValue&lt;/code&gt; 를 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get/set&lt;/code&gt; 할 수 있습니다. 값이 변경되었을 때, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;View&lt;/code&gt; 를 다시 그립니다.

아주아주아주 많은 곳에서 쓸 수 있음.

&lt;strong&gt;진실의&lt;/strong&gt; 단일 소스를 가지게 한다는 점에서, MVVM 패턴에서 매우 중요한 역할을 합니다.

&lt;ul&gt;
  &lt;li&gt;데이터는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ViewModel&lt;/code&gt; 이 가지고 있지만, 이 데이터는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;View&lt;/code&gt; 에서도 제어하기도 함. (둘 중 뭐가 진짜게?)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;View&lt;/code&gt; 에서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stored property&lt;/code&gt; 를 추가하는 것이 아닌, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ViewModel&lt;/code&gt; 의 변수를 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Biniding&lt;/code&gt; 하여 사용 할 수 있다. 한 쪽에서 바뀌면, 둘 다 바뀌기 때문에 둘 다 진짜가 된당!&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OtherView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;@Binding&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;sharedText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// @State가 아닌 @Binding으로 선언&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sharedText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MyView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;@State&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;myString&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Hello&quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;OtherView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;sharedText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// myString을 OtherView와 연결&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;상수값을-binding하기&quot;&gt;상수값을 Binding하기&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;OtherView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;sharedText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;constant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Howdy&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;computed-binding&quot;&gt;Computed Binding&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;OtherView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;sharedText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;environmentobject&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@EnvironmentObject&lt;/code&gt;&lt;/h2&gt;

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@ObservedObject&lt;/code&gt; 랑 유사한데, 넘겨주는 방식이 다릅니다.

&lt;h3 id=&quot;observedobject-1&quot;&gt;ObservedObject&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MyView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;@ObservedObject&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;viewModel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ViewModelClass&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;myView&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MyView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;viewModel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;theViewModel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;environmentobject-1&quot;&gt;EnvironmentObject&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MyView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;@EnvironmentObject&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;viewModel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ViewModelClass&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;myView&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MyView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;environmentObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;theViewModel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

가장 큰 차이점!

상위 뷰에서 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@EnvironmentObject&lt;/code&gt; 를 선언하면, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;body&lt;/code&gt; 내부의 모든 뷰에서 (모달로 띄운 거 말고) 접근할 수 있다!!!!!!

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;View&lt;/code&gt; 하나에서 같은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ObservableObject&lt;/code&gt; 타입의 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@EnvironmentObject&lt;/code&gt; 는 하나만 존재할 수 있다.

기본적으로 wrappedValue 와 동작방식은 ObservableObject 와 같다!

&lt;h3 id=&quot;environment&quot;&gt;Environment&lt;/h3&gt;

EnvironmentObject 랑 연관없음!

View의 환경적인 요소값들에 대해 읽어오는 Property Wrapper.

&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[EnvironmentValue](https://developer.apple.com/documentation/swiftui/environmentvalues)&lt;/code&gt; 타입인 KeyPath를 받아서 해당 값에 접근한다.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Environment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DynamicProperty&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;keyPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;KeyPath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;EnvironmentValues&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;wrappedValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// projected value는 없습니당.&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// property&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;@Environment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lineLimit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;lineLimit&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 값을 변경하고 싶을 때는 이렇게&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;MyView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(\&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lineLimit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 혹은 이렇게 축약해&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;custom-environment&quot;&gt;Custom Environment&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MyEnvironmentKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;EnvironmentKey&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;defaultValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Default value&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;EnvironmentValues&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// EnvironmentValues 에 커스텀 키 값 추가&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;myCustomValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;MyEnvironmentKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;MyEnvironmentKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newValue&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;myCustomValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;myCustomValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;myCustomValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCustomValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;publisher-맛보기&quot;&gt;Publisher 맛보기&lt;/h1&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;publisher&quot;&gt;Publisher?&lt;/h2&gt;

일반적으로는 값을 내보내는데, 만약 실패한다면 실패 값을 내보내는 녀석. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Combine&lt;/code&gt; 에 정의되어 있음.

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Publisher&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Publisher&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Wrapped&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Failure&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Never&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Never Failure. Never ends.&lt;/span&gt;

        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Optional&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Wrapped&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Publisher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Optional&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Wrapped&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Publisher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt;

        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;subscriber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Wrapped&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Subscriber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Failure&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Never&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

비슷한 예를 찾자면, Rx의 Observable, Subject, Relay 와 유사함.

성공/실패/오류 에 대해 이전에는 오류를 던지는(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;throw&lt;/code&gt;) 하는 방식으로 구현되었다면, 이제는 그러한 실패/오류 까지도 하나의 타입으로 명시하여 처리하는 방식

&lt;h2 id=&quot;listening-publisher&quot;&gt;Listening Publisher&lt;/h2&gt;

&lt;h3 id=&quot;publishersinkreceivecompletion-receivevalue&quot;&gt;Publisher.sink(receiveCompletion:, receiveValue:)&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;cancellable&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myPublisher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;       &lt;span class=&quot;c1&quot;&gt;// Sink returns that implements the Cancellabe protocol&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;receiveCompletion&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; 
  &lt;span class=&quot;nv&quot;&gt;receiveValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;thingThePubliserPublishes&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Cancellable :: publisher에 대한 listening을 중단할 수 있음!
    &lt;ul&gt;
      &lt;li&gt;바꿔말하면 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cancel()&lt;/code&gt; 을 호출하기 전까지 계속 연결되어 있을 것이라는점 🙂&lt;/li&gt;
      &lt;li&gt;release 될 때 stop 되면서 날라가버리므로 연결 라이프사이클과 함께 유지되는 instance property로 사용하는 것은 어떨까~?&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;viewonreceivepublisher-perform&quot;&gt;View.onReceive(publisher:, perform:)&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;onReceive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;publisher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;thingThePublisherPublishes&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// do something!&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// At this time your View will be invalidated automaticallly.&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;어디서-사용되나요&quot;&gt;어디서 사용되나요?&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;오 아까 위에서 봣쥬? @Publisher 의 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;projectedValue&lt;/code&gt; 의 타입이 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Publisher&lt;/code&gt; 입니당.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLSession.dataTaskPublisher&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Timer.publish(every:)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NotificationCenter.publisher(for:)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;등등등~!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;urlsessiondatataskpublisher&quot;&gt;URLSession.dataTaskPublisher&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ViewModel&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;@Published&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;backgroundImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UIImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;
	
	&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;fetchImageCancellable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AnyCancellable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fetchImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;stopLoadImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URLSession&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shared&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;publisher&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dataTaskPublisher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		               &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urlResponse&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UIImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// 이미지로 변환&lt;/span&gt;
		               &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DispatchQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// main queue에서 받기&lt;/span&gt;
		               &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;replaceError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;// Error가 떨어질 경우 nil을 넘겨줌.&lt;/span&gt;
		&lt;span class=&quot;c1&quot;&gt;// let canceller = publisher.assign(to: `\ViewModel.backgroundImage, on: self)&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;fetchImageCancellable&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;publisher&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;backgroundImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 어디에 있는지 명시해줬기 때문에 생략가능&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;stopLoadImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;n&quot;&gt;fetchImageCancellable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cancel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; 
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ViewModel&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;@Published&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;backgroundImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UIImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;
	
	&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;fetchImageCancellable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AnyCancellable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fetchImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;stopLoadImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;fetchImageCancellable&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URLSession&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;share&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dataTaskPublisher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		               &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urlResponse&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UIImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// 이미지로 변환&lt;/span&gt;
		               &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DispatchQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// main queue에서 받기&lt;/span&gt;
		               &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;replaceError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                   &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;backgroundImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 어디에 있는지 명시해줬기 때문에 생략가능&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;stopLoadImage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;n&quot;&gt;fetchImageCancellable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cancel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; 
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

Chaining 가능!

&lt;h3 id=&quot;참조&quot;&gt;참조&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=mz-rNLWJ0bk&amp;amp;list=PLpGHT1n4-mAtTj9oywMWoBx0dCGd51_yG&amp;amp;index=9&quot;&gt;원본영상&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Mon, 08 Mar 2021 15:26:06 +0000</pubDate>
        <link>https://caution-dev.github.io/ios/2021/03/08/SwiftUI-Data-Flow.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/ios/2021/03/08/SwiftUI-Data-Flow.html</guid>
        
        <category>iOS</category>
        
        <category>Swift</category>
        
        <category>SwiftUI</category>
        
        <category>Combine</category>
        
        
        <category>iOS</category>
        
      </item>
    
      <item>
        <title></title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#trait&quot; id=&quot;markdown-toc-trait&quot;&gt;Trait&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#size-class&quot; id=&quot;markdown-toc-size-class&quot;&gt;Size Class&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#adaptivity-and-size-changes&quot; id=&quot;markdown-toc-adaptivity-and-size-changes&quot;&gt;Adaptivity and Size Changes&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#the-adaptive-model-문서-요약&quot; id=&quot;markdown-toc-the-adaptive-model-문서-요약&quot;&gt;The Adaptive Model 문서 요약&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#building-an-adaptive-interface-문서-요약adaptive-ui를-적용하는-프로세스&quot; id=&quot;markdown-toc-building-an-adaptive-interface-문서-요약adaptive-ui를-적용하는-프로세스&quot;&gt;Building an Adaptive Interface 문서 요약(Adaptive UI를 적용하는 프로세스)&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#example-in-whale&quot; id=&quot;markdown-toc-example-in-whale&quot;&gt;Example in Whale&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#기존의-ui를-adaptive-ui로-변경-in-tablistgridflowlayout&quot; id=&quot;markdown-toc-기존의-ui를-adaptive-ui로-변경-in-tablistgridflowlayout&quot;&gt;기존의 UI를 Adaptive UI로 변경 in TabListGridFlowLayout&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#uiscreen을-기준으로-layout을-결정하는-부분-변경-in-tabpagecontrolview&quot; id=&quot;markdown-toc-uiscreen을-기준으로-layout을-결정하는-부분-변경-in-tabpagecontrolview&quot;&gt;UIScreen을 기준으로 layout을 결정하는 부분 변경 in TabPageControlView&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#viewwilltransitiontowith-in-tablistgridviewcontroller&quot; id=&quot;markdown-toc-viewwilltransitiontowith-in-tablistgridviewcontroller&quot;&gt;viewWillTransition(to:with:) in TabListGridViewController&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#참조&quot; id=&quot;markdown-toc-참조&quot;&gt;참조&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

안녕하세요! caution입니다.

iOS 개발자는 OS의 주체인 Apple의 의도를 파악하는 것이 가장 중요하다고 생각합니다.&lt;br /&gt;
그래서 Apple에서 가이드하는 Adaptive UI를 통해 Whale이 Universal로 가는 길을 제시하고자 합니다.

Adaptive UI의 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;adaptive&lt;/code&gt;는 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;모든 iOS 디바이스에 잘 맞도록 콘텐츠를 조정할 수 있음&lt;/code&gt;을 의미합니다.&lt;br /&gt;
Adaptive UI는 모든 iOS 디바이스에서 Whale의 디자인과 기획에 담긴 의도를 사용자에게 온전히 전달하기 위한 최고의 방법입니다.

Whale이 Universal로 나아가기 위해서는 아래의 &lt;strong&gt;두 가지 이슈&lt;/strong&gt;를 해결해야 합니다.
&lt;ol&gt;
  &lt;li&gt;Apple에서 가이드 해주는 Adaptive Model을 통해 기존의 UI를 Adaptive UI로 변경&lt;/li&gt;
  &lt;li&gt;layout을 결정할 때 UIScreen을 기준으로 하던 기존 로직들에 대한 수정&lt;/li&gt;
&lt;/ol&gt;

해당 문서는 &lt;a href=&quot;https://oss.navercorp.com/whale/Mobile-Spec/issues/667&quot;&gt;iPad 버전 진행 이슈 #667&lt;/a&gt;의 iPad의 Split View 대응을 위한 Adaptive UI 및 관련 지식인 Trait과 Size Class에 관한 문서입니다.&lt;br /&gt;
Adaptive UI의 세세한 내용은 &lt;a href=&quot;https://developer.apple.com/design/adaptivity/&quot;&gt;Building Adaptive User Interfaces&lt;/a&gt;에 리소스들이 모여있으니 참고 부탁드리겠습니다.

&lt;h2 id=&quot;trait&quot;&gt;Trait&lt;/h2&gt;
&lt;a href=&quot;https://developer.apple.com/documentation/uikit/uitraitenvironment&quot;&gt;UITraitEnvironment&lt;/a&gt; protocol을 따르는 UIViewController, UIView 같은 객체들은 해당 객체와 관련된 현재 environment을 나타내는 trait(특성)들로 이루어진 &lt;a href=&quot;https://developer.apple.com/documentation/uikit/uitraitenvironment/1623514-traitcollection&quot;&gt;traitCollection&lt;/a&gt;이라는 property를 갖고 있습니다.

trait의 종류는 아래와 같습니다.
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/uikit/uitraitcollection/1623508-horizontalsizeclass&quot;&gt;horizontalSizeClass&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/uikit/uitraitcollection/1623513-verticalsizeclass&quot;&gt;verticalSizeClass&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/uikit/uitraitcollection/1623519-displayscale&quot;&gt;displayScale&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/uikit/uitraitcollection/1623521-userinterfaceidiom&quot;&gt;userInterfaceIdiom&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

여기에서는 trait이 &lt;strong&gt;trait을 갖는 객체와 관련된 현재 environment를 나타낸다는 것&lt;/strong&gt;과 바로 다음에 설명할 &lt;strong&gt;Size Class가 하나의 trait이라는 것&lt;/strong&gt;만 알아가시면 되겠습니다.

&lt;h2 id=&quot;size-class&quot;&gt;Size Class&lt;/h2&gt;
Size Class는 크기에 따라 콘텐츠 영역에 자동으로 할당되는 하나의 trait입니다.&lt;br /&gt;
apple은 adaptive한 UI를 위하여 이 Size Class의 사용을 권장하고 있습니다.

시스템은 뷰의 넓이와 높이를 2가지 종류의 Size Class로 정의합니다.

&lt;ul&gt;
  &lt;li&gt;compact(denotes constrained space)&lt;/li&gt;
  &lt;li&gt;regular(denotes expansive space)&lt;/li&gt;
&lt;/ul&gt;

뷰는 아래와 같이 4가지의 Size Class의 조합을 갖습니다.
&lt;ul&gt;
  &lt;li&gt;regular width, regular height&lt;/li&gt;
  &lt;li&gt;compact width, compact height&lt;/li&gt;
  &lt;li&gt;regular width, compact height&lt;/li&gt;
  &lt;li&gt;compact width, regular height&lt;/li&gt;
&lt;/ul&gt;

traitCollection을 통해 view가 가진 &lt;a href=&quot;https://developer.apple.com/documentation/uikit/uitraitcollection/1623508-horizontalsizeclass&quot;&gt;horizontalSizeClass&lt;/a&gt;, &lt;a href=&quot;https://developer.apple.com/documentation/uikit/uitraitcollection/1623513-verticalsizeclass&quot;&gt;verticalSizeClass&lt;/a&gt;를 알 수 있습니다.

기기별, 상황별 Size Class에 관련된 자세한 설명은 &lt;a href=&quot;https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/&quot;&gt;Human Interface Guidelines의 Adaptivity and Layout&lt;/a&gt;의 Size Classes에서 확인하실 수 있습니다.

&lt;h2 id=&quot;adaptivity-and-size-changes&quot;&gt;Adaptivity and Size Changes&lt;/h2&gt;
&lt;h3 id=&quot;the-adaptive-model-문서-요약&quot;&gt;&lt;a href=&quot;https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html#//apple_ref/doc/uid/TP40007457-CH19-SW1&quot;&gt;The Adaptive Model&lt;/a&gt; 문서 요약&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;iOS의 Adaptive Model을 이용하면 어떤 디바이스에서도 잘 맞도록 콘텐츠를 조정할 수 있다.&lt;/li&gt;
  &lt;li&gt;Adaptive Interface를 만들 때 가장 중요한 것은 Auto Layout이다.&lt;/li&gt;
  &lt;li&gt;고수준의 결정은 trait을 이용한다.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;building-an-adaptive-interface-문서-요약adaptive-ui를-적용하는-프로세스&quot;&gt;&lt;a href=&quot;https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/BuildinganAdaptiveInterface.html#//apple_ref/doc/uid/TP40007457-CH32-SW1&quot;&gt;Building an Adaptive Interface&lt;/a&gt; 문서 요약(Adaptive UI를 적용하는 프로세스)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;traitCollectionDidChange(_:)&lt;/code&gt; 같은 메소드를 통해) trait이 변경될 때 interface의 굵직한 부분들을 결정&lt;/li&gt;
  &lt;li&gt;Interface Builder 혹은 code로 Size Class별 Constraint를 걸어 &lt;strong&gt;Size Class를 기준으로 layout을 결정&lt;/strong&gt;하도록 대응&lt;/li&gt;
  &lt;li&gt;Auto Layout Constraint로도 안되는 부분은 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;viewWillTransition(to:with:)&lt;/code&gt;를 통해 추가 대응&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;example-in-whale&quot;&gt;Example in Whale&lt;/h2&gt;
Adaptive UI의 골자는 layout을 iPhone, iPad와 같은 idiom으로 결정하는 것이 아니라 Size Class를 기준으로 결정하는 것입니다.

왜 Size Class를 써야 할까요?&lt;br /&gt;
Size Class를 사용하면 iPad의 Split View에서 다양하게 변하는 window 크기에 쉽게 대응할 수 있고,&lt;br /&gt;
이는 브라우저인 Whale이 반드시 지원해야 하는 &lt;a href=&quot;https://developer.apple.com/design/human-interface-guidelines/ios/system-capabilities/multiple-windows/&quot;&gt;multiple windows&lt;/a&gt;를 적용하기 위한 초석이 되기 때문입니다.

또한 &lt;a href=&quot;https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/TheAdaptiveModel.html#//apple_ref/doc/uid/TP40007457-CH19-SW1&quot;&gt;The Adaptive Model&lt;/a&gt;에서는 trait 중 하나인 &lt;a href=&quot;https://developer.apple.com/documentation/uikit/uitraitcollection/1623521-userinterfaceidiom&quot;&gt;userInterfaceIdiom&lt;/a&gt;의 역할을 아래와 같이 가이드하고 있습니다.
&lt;blockquote&gt;
  This trait is provided for backward compatibility and conveys the type of device on which your app is running. Avoid using this trait as much as possible. For layout decisions, use the horizontal and vertical size classes instead.&lt;br /&gt;
이 trait은 이전 버전과의 호환성을 위해 제공되며 앱이 실행되는 디바이스의 유형을 전달합니다. 이 특성을 가능한 한 많이 사용하지 마십시오. layout을 결정하기 위해서는 Size Class를 대신 사용하십시오.
&lt;/blockquote&gt;

아래 예제는 아래의 &lt;strong&gt;두 가지 문제점&lt;/strong&gt;을 해결하여 탭 리스트를 Split View에 대응한 것입니다.
&lt;ol&gt;
  &lt;li&gt;idiom(디바이스의 종류)을 기준으로 layout을 결정한다.&lt;/li&gt;
  &lt;li&gt;UIScreen(디바이스의 크기)을 기준으로 layout을 결정한다.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;기존의-ui를-adaptive-ui로-변경-in-tablistgridflowlayout&quot;&gt;기존의 UI를 Adaptive UI로 변경 in TabListGridFlowLayout&lt;/h3&gt;
&lt;strong&gt;변경 전, idiom을 기준으로 layout을 결정하는 기존의 로직:&lt;/strong&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;struct TabGridCellInfo {

    static var size: CGSize {
        if UI_USER_INTERFACE_IDIOM() == .pad {
            return CGSize(width: 166, height: 200)
        } else {
            if UIScreen.isSmallLayout {
                let defaultSize = self.defaultSize
                return CGSize(width: defaultSize.width * 0.8, height: defaultSize.height * 0.8)
            } else {
                return self.defaultSize
            }
        }
    }

    static var defaultSize: CGSize {
        return CGSize(width: 161, height: 195)
    }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;class TabListGridFlowLayout: UICollectionViewLayout {

    ...

    var numberOfTabColumns: Int {
        if UI_USER_INTERFACE_IDIOM() == .pad {
            if UIApplication.isStatusBarLandscape {
                return 4
            } else {
                return 3
            }
        } else {
            if UIApplication.isStatusBarLandscape {
                return UIDevice.isBigPhone ? 4 : 3
            } else {
                return 2
            }
        }
    }

    ...

}
&lt;/code&gt;&lt;/pre&gt;

&lt;strong&gt;변경 후, Size Class을 기준으로 layout을 결정하는 로직:&lt;/strong&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;internal struct AdaptiveGridCellInfo {

    // MARK: - internal

    internal static func verticalScrollItemSize(
        of collectionView: UICollectionView,
        defaultSize: CGSize,
        columnCount: Int,
        insets: UIEdgeInsets = .zero,
        interItemSpacing: CGFloat = 0.0
    ) -&amp;gt; CGSize {
        let totalInsets = insets.left + insets.right
        let totalSpacing = interItemSpacing * CGFloat(columnCount - 1)
        let ratio = defaultSize.height / defaultSize.width
        let width = (collectionView.bounds.width - totalInsets - totalSpacing) / CGFloat(columnCount)

        return CGSize(width: width, height: width * ratio)
    }

    ...

}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;extension CGSize {

    internal var reversed: CGSize {
        return CGSize(width: self.height, height: self.width)
    }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;class TabListGridFlowLayout: UICollectionViewLayout {

    ...

    private var itemSize: CGSize {
        guard let collectionView = collectionView else {
            return .zero
        }

        let isRegular = collectionView.traitCollection.horizontalSizeClass == .regular
        let isLandscape = collectionView.frame.width &amp;gt; collectionView.frame.height
        let defaultSize = CGSize(width: 161, height: 195)

        return AdaptiveGridCellInfo.verticalScrollItemSize(
            of: collectionView,
            defaultSize: isRegular &amp;amp;&amp;amp; isLandscape ? defaultSize.reversed : defaultSize,
            columnCount: self.columnCount,
            insets: self.edgeInsets,
            interItemSpacing: self.interItemSpacing
        )
    }

    private var columnCount: Int {
        guard let collectionView = collectionView else {
            return 0
        }

        let isSmallScreen = max(UIScreen.mainScreenWidth, UIScreen.mainScreenHeight) &amp;lt; 736.0
        let isCompact = collectionView.traitCollection.horizontalSizeClass == .compact
        let isPortrait = collectionView.frame.width &amp;lt; collectionView.frame.height

        return isCompact &amp;amp;&amp;amp; isPortrait ? 2 : (isSmallScreen ? 3 : 4)
    }

    ...

}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;uiscreen을-기준으로-layout을-결정하는-부분-변경-in-tabpagecontrolview&quot;&gt;UIScreen을 기준으로 layout을 결정하는 부분 변경 in TabPageControlView&lt;/h3&gt;
&lt;strong&gt;변경 전, UIScreen을 기준으로 layout을 결정하는 기존의 로직:&lt;/strong&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;class TabPageControlView: UIView {

    ...

    override func sizeThatFits(_ size: CGSize) -&amp;gt; CGSize {
        let width = UIScreen.mainScreenWidth

        ...

        return CGSize(width: width, height: self.height)
    }

    private var height: CGFloat {
        return UIApplication.isStatusBarLandscape ? 53.0 : 43.0
    }

    ...

}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;class TabListViewController: UIViewController, ReplaceAttachable, CommandBroker {

    ...

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        ...

        self.tabPageControl.sizeToFit()

        ...

    }

    ...

}
&lt;/code&gt;&lt;/pre&gt;

&lt;strong&gt;변경 후, super view의 bounds를 기준으로 layout을 결정하는 로직:&lt;/strong&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;class TabPageControlView: UIView {

    ...

    /*override func sizeThatFits(_ size: CGSize) -&amp;gt; CGSize {
        let width = UIScreen.mainScreenWidth

        ...

        return CGSize(width: width, height: self.height)
    }*/

    /*private var height: CGFloat {
        return UIApplication.isStatusBarLandscape ? 53.0 : 43.0
    }*/

    ...

}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;class TabListViewController: UIViewController, ReplaceAttachable, CommandBroker {

    ...

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        ...

        self.tabPageControl.frame.size = CGSize(
            width: self.view.bounds.width,
            height: UIApplication.isStatusBarLandscape ? 53.0 : 43.0
        )

        ...

    }

    ...

}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;viewwilltransitiontowith-in-tablistgridviewcontroller&quot;&gt;viewWillTransition(to:with:) in TabListGridViewController&lt;/h3&gt;
&lt;strong&gt;변경 후, transition이 일어나면 탭 리스트를 layout 정보를 업데이트하는 로직:&lt;/strong&gt;
&lt;pre&gt;&lt;code class=&quot;language-Swift&quot;&gt;class TabListGridViewController: UICollectionViewController, TabListExpressible, TabListScrollPositionProvider {

    …

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)

        coordinator.animate(alongsideTransition: { _ in
            self.collectionView.collectionViewLayout.invalidateLayout()
        })
    }

    …

}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;참조&quot;&gt;참조&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://minsone.github.io/mac/ios/swift-automatic-reference-counting-summary&quot;&gt;ARC Summary&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sun, 02 Feb 2020 15:26:06 +0000</pubDate>
        <link>https://caution-dev.github.io/ios/2020/02/02/AdaptivUI.html</link>
        <guid isPermaLink="true">https://caution-dev.github.io/ios/2020/02/02/AdaptivUI.html</guid>
        
        <category>iOS</category>
        
        <category>Swift</category>
        
        <category>iPadOS</category>
        
        <category>AdaptiveUI</category>
        
        
        <category>iOS</category>
        
      </item>
    
  </channel>
</rss>
