tag:blogger.com,1999:blog-51941136622730411852024-02-19T15:21:49.179+09:00Anything NewIt's How differentyou_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comBlogger174125tag:blogger.com,1999:blog-5194113662273041185.post-2976731766225596502019-09-23T11:11:00.000+09:002019-09-23T11:11:28.326+09:00MVVM with Combineチュートリアル for iOS<h1 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.8em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
MVVM with Combine Tutorial for iOS</h1>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
このMVVM with Combineチュートリアルでは、CombineフレームワークとSwiftUIを使用して、MVVMパターンを使用してアプリを構築する方法を学習します。今回は良質なiOS開発のチュートリアルを数多く紹介している <a href="https://www.raywenderlich.com/" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">raywenderlich</a>の記事を翻訳、加筆修正したものになります。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
今回のチュートリアルで使うファイルのダウンロードはこちらから<br style="box-sizing: inherit;" /><a href="https://koenig-media.raywenderlich.com/uploads/2019/09/CombineWeatherApp.zip" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">資料のダウンロード</a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
機能追加含め全体を網羅したリポジトリはこちらです。<br style="box-sizing: inherit;" /><a class="autolink" href="https://github.com/manchan/MVVM-with-Combine-Tutorial-for-iOS" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">https://github.com/manchan/MVVM-with-Combine-Tutorial-for-iOS</a></div>
<h1 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.8em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="参照記事" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#%E5%8F%82%E7%85%A7%E8%A8%98%E4%BA%8B" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>参照記事</h1>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<a href="https://www.raywenderlich.com/4161005-mvvm-with-combine-tutorial-for-ios" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">MVVM with Combine Tutorial for iOS By Rui Peres</a></div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="version" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#version" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>version</h2>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<span style="box-sizing: inherit; font-weight: 700;">Swift 5, iOS 13, Xcode 11</span></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<span style="box-sizing: inherit; font-weight: 700;">※このチュートリアルには、Xcode 11が必要です。</span></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
Appleの最新のフレームワークであるCombineは、SwiftUIと並んでWWDCを席巻しました。 Combineは、値を出力し、オプションで成功またはエラーで終了する論理的なデータストリームを提供するフレームワークです。これらのストリームは、近年人気が高まっているFunctional Reactive Programming(FRP)の中核にあります。 Appleは、SwiftUIとのインターフェースを作成する宣言的な方法だけでなく、Combineを使用して状態を長期にわたって管理することで前進していることが明らかになりました。このMVVM with Combineチュートリアルでは、SwiftUI、Combine、MVVMをアーキテクチャパターンとして利用する天気アプリを作成します。それが終わるまでには、次のことに満足感を得るでしょう。</div>
<ul style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;">Combineを使用して状態を管理します。</li>
<li style="box-sizing: inherit;">SwiftUIを使用してUIとViewModeの間にバインディングを作成します。</li>
<li style="box-sizing: inherit;">これら3つの概念がすべてどのように適合するかを理解する。</li>
</ul>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
このチュートリアルの終わりまでに、アプリは次のようになります。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/f61d4e4e02d34d434adf75f43679df7927f72016/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f33656563383133642d636639352d323238322d386535372d3664396537326131393562372e676966" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="weather_final-1.gif" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/3eec813d-cf95-2282-8e57-6d9e72a195b7.gif" src="https://camo.qiitausercontent.com/f61d4e4e02d34d434adf75f43679df7927f72016/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f33656563383133642d636639352d323238322d386535372d3664396537326131393562372e676966" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
また、この特定のアプローチの長所と短所、および問題に異なる方法で取り組む方法についても説明します。 このように、あなたの道に来るいかなる問題に対して何でもよりよく準備されています! :]</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="初めに" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#%E5%88%9D%E3%82%81%E3%81%AB" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>初めに</h2>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
このチュートリアルの上部にある[資料のダウンロード]リンクを使用して、プロジェクト資料をダウンロードすることから始めます。 CombineWeatherApp-Starterフォルダー内にあるプロジェクトを開きます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
天気情報を表示するには、<a href="https://openweathermap.org/appid" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">OpenWeatherMap</a>に登録してAPIキーを取得する必要があります。このプロセスは数分で完了し、最後には次のような画面が表示されます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/b880edcfdfffcfd72528cbd98be0268e2bcaf16f/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f38663864306464352d323262352d366161622d323036322d3136363730343235393563622e706e67" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="OpenWeatherInterface-650x294.png" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/8f8d0dd5-22b5-6aab-2062-1667042595cb.png" src="https://camo.qiitausercontent.com/b880edcfdfffcfd72528cbd98be0268e2bcaf16f/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f38663864306464352d323262352d366161622d323036322d3136363730343235393563622e706e67" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeatherFetcher.swift</code> を開きます。次に、WeatherFetcher.OpenWeatherAPIをOpenWeatherAPI構造体内のキーで更新します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeatherFetcher.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">struct</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">OpenWeatherAPI</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">...</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">static</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">key</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">"<your key="">"</your></span> <span class="c1" style="box-sizing: inherit; color: #9dabae;">// Replace with your own API Key</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
これが完了したら、プロジェクトをビルドして実行します。メイン画面には、タップするボタンが表示されます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/c2e53360e908675bbf8ec70d8753433a5673c279/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f61353362363066372d633838632d316237362d346561622d3135633465666331373338382e706e67" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="MainScreen_start-281x500.png" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/a53b60f7-c88c-1b76-4eab-15c4efc17388.png" src="https://camo.qiitausercontent.com/c2e53360e908675bbf8ec70d8753433a5673c279/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f61353362363066372d633838632d316237362d346561622d3135633465666331373338382e706e67" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
「ベスト天気アプリ」をタップすると、詳細が表示されます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/85db5e67415ef2786e0c34e7589bc9153ebff9c3/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f66626662376465662d396564322d373961302d623263632d3162333032393536636664612e706e67" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="DetailScreen_finished-281x500.png" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/fbfb7def-9ed2-79a0-b2cc-1b302956cfda.png" src="https://camo.qiitausercontent.com/85db5e67415ef2786e0c34e7589bc9153ebff9c3/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f66626662376465662d396564322d373961302d623263632d3162333032393536636664612e706e67" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
現時点ではそれほど見栄えが良くありませんが、チュートリアルの終わりまでには見栄えがよくなります。 :]</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="mvvmパターンの紹介" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#mvvm%E3%83%91%E3%82%BF%E3%83%BC%E3%83%B3%E3%81%AE%E7%B4%B9%E4%BB%8B" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>MVVMパターンの紹介</h2>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<span style="box-sizing: inherit; font-weight: 700;">Model-View-ViewModel(MVVM)</span>パターンは、UIデザインパターンです。これは、集合的にMV*として知られるパターンのより大きなファミリーのメンバーです。これらには、<a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">モデルビューコントローラー(MVC)</a>、<a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">モデルビュープレゼンター(MVP)</a>などが含まれます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
これらの各パターンは、アプリの開発とテストを容易にするために、UIロジックをビジネスロジックから分離することに対処します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
パターンをよりよく理解するために、MVVMの起源を振り返るのに役立ちます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
MVCは最初のUIデザインパターンであり、その起源は1970年代の<a href="https://ja.wikipedia.org/wiki/Smalltalk" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">Smalltalk言語</a>にまでさかのぼります。以下の画像は、MVCパターンの主要なコンポーネントを示しています。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/a4dd5257f9806d8403adcbb564441fbec88b9cc7/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f35633231356334662d366262302d376265342d633761332d3331633664353832643461382e706e67" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="MVCPattern-2.png" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/5c215c4f-6bb0-7be4-c7a3-31c6d582d4a8.png" src="https://camo.qiitausercontent.com/a4dd5257f9806d8403adcbb564441fbec88b9cc7/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f35633231356334662d366262302d376265342d633761332d3331633664353832643461382e706e67" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
このパターンは、UIを、アプリケーションの状態を表すモデル、UIコントロールで構成されるビュー、およびユーザーの対話を処理し、それに応じてモデルを更新するコントローラーに分割します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
MVCパターンの1つの大きな問題は、非常に紛らわしいことです。 概念は良く見えますが、多くの場合、人々がMVCを実装するようになると、上に示した一見循環的な関係により、モデル、ビュー、コントローラーが大きくて恐ろしい混乱になります。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
最近では、Martin Fowlerは、<a href="https://martinfowler.com/eaaDev/PresentationModel.html" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">プレゼンテーションモデル</a>と呼ばれるMVCパターンのバリエーションを導入しました。これは、Microsoftによって <span style="box-sizing: inherit; font-weight: 700;">MVVM</span> という名前で採用され、普及しました。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/2f113feaa6e66016a3533478c688fa682c5ca0cb/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f63393064373761382d623161622d303361662d653065312d6361393362373864366335392e706e67" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="MVVMPattern.png" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/c90d77a8-b1ab-03af-e0e1-ca93b78d6c59.png" src="https://camo.qiitausercontent.com/2f113feaa6e66016a3533478c688fa682c5ca0cb/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f63393064373761382d623161622d303361662d653065312d6361393362373864366335392e706e67" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
このパターンの中心となるのは、アプリのUI状態を表す特別なタイプのモデルである <span style="box-sizing: inherit; font-weight: 700;">ViewModel</span>です。 各UIコントロールの状態を詳述するプロパティが含まれています。 たとえば、テキストフィールドの現在のテキスト、または特定のボタンが有効かどうか。 また、ボタンタップやジェスチャなど、ビューが実行できるアクションも公開します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
ViewModelをビューのモデルと考えると役立ちます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
MVVMパターンの3つのコンポーネント間の関係は、MVCの同等のものよりも単純であり、以下の厳格な規則に従います。</div>
<ol style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;">ビューにはViewModelへの参照がありますが、その逆はありません。</li>
<li style="box-sizing: inherit;">ViewModelにはモデルへの参照がありますが、その逆はありません。</li>
<li style="box-sizing: inherit;">ビューにはモデルへの参照はなく、その逆もありません。</li>
</ol>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
これらのルールを破ると、MVVMが間違っていることになります!</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
このパターンの直接的な利点は次のとおりです。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<span style="box-sizing: inherit; font-weight: 700;">軽量ビュー</span>:すべてのUIロジックはViewModel内にあるため、非常に軽量なビューになります。<br style="box-sizing: inherit;" /><span style="box-sizing: inherit; font-weight: 700;">テスト</span>:ビューなしでアプリ全体を実行できるため、テスト性が大幅に向上します。</div>
<div class="code-frame" data-lang="text" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;">注:テストは小規模で含まれるコードチャンクとして実行されるため、ビューのテストは難しいことで有名です。
通常、コントローラーは、他のアプリの状態に依存するビューをシーンに追加および構成します。
これは、小さなテストの実行が脆弱で扱いにくい命題になる可能性があることを意味します。
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
この時点で、問題を発見した可能性があります。ビューにViewModelへの参照があり、その逆にはない場合、ViewModelはどのようにビューを更新しますか?</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
そう!これが、MVVMパターンの秘密の出番です。</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="mvvmとデータバインディング" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#mvvm%E3%81%A8%E3%83%87%E3%83%BC%E3%82%BF%E3%83%90%E3%82%A4%E3%83%B3%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>MVVMとデータバインディング</h2>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<span style="box-sizing: inherit; font-weight: 700;">データバインディング</span>は、ViewをViewModelに接続できるようにするものです。 今年のWWDC以前は、<a href="https://github.com/ReactiveX/RxSwift" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">RxSwift</a>(RxCocoa経由)または<a href="https://github.com/ReactiveCocoa/ReactiveSwift" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">ReactiveSwift</a>(ReactiveCocoa経由)に似たものを使用する必要がありました。 このチュートリアルでは、SwiftUIとCombineを使用してこの接続を実現する方法を探ります。</div>
<h3 style="background-color: white; box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.4em; line-height: 1.5; margin: 2.2em 0px 2.4rem; position: relative;">
<span class="fragment" id="mvvm-with-combine" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#mvvm-with-combine" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>MVVM With Combine</h3>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
コンバインは実際にバインディングを行うために必要ではありませんが、その力を利用できないという意味ではありません。 SwiftUIを単独で使用してバインディングを作成できます。 ただし、Combineを使用するとより多くのパワーが得られます。 チュートリアル全体で見るように、ViewModel側にいれば、Combineを使用することが自然な選択になります。 これにより、UIで開始するチェーンをネットワークコールに至るまで明確に定義できます。 (意図した)SwiftUIとCombineを組み合わせることにより、このすべての機能を簡単に実現できます。 別の通信パターン(Delegateなど)を使用することもできますが、そうすることで、SwiftUIによって設定された宣言型アプローチとそのバインディングを命令型と交換しています。</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="アプリを構築" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#%E3%82%A2%E3%83%97%E3%83%AA%E3%82%92%E6%A7%8B%E7%AF%89" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>アプリを構築</h2>
<div class="code-frame" data-lang="text" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;">注:SwiftUIやCombineなどを初めて使用する場合、一部のスニペットに混乱する可能性があります。
その場合でも心配しないでください! これは高度なトピックであり、ある程度の時間と練習が必要です。
理解できない場合は、アプリを実行してブレークポイントを設定し、動作を確認してください。
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
モデルレイヤーから始めて、UIに移動します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://openweathermap.org/" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">OpenWeatherMap</a> APIからのJSONを扱っているため、データをデコードされたオブジェクトに変換するユーティリティメソッドが必要です。 <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Parsing.swift</code> を開き、次を追加します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">Parsing.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">import</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Foundation</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">import</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Combine</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="n" style="box-sizing: inherit;">decode</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">T</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Decodable</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">_</span> <span class="nv" style="box-sizing: inherit;">data</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Data</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">-></span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyPublisher</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">T</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherError</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">decoder</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">JSONDecoder</span><span class="p" style="box-sizing: inherit;">()</span>
<span class="n" style="box-sizing: inherit;">decoder</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dateDecodingStrategy</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">secondsSince1970</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Just</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">data</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">decode</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">type</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">T</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nv" style="box-sizing: inherit;">decoder</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">decoder</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">mapError</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="n" style="box-sizing: inherit;">error</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">parsing</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">description</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">error</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">localizedDescription</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">eraseToAnyPublisher</span><span class="p" style="box-sizing: inherit;">()</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
これは、標準の<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">JSONDecoder</code>を使用して、<a href="https://openweathermap.org/" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">OpenWeatherMap</a> APIからJSONをデコードします。 <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">mapError(_ :)</code>および<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">eraseToAnyPublisher()</code>の詳細については、後ほど説明します。</div>
<blockquote style="background-color: white; border-left: 5px solid rgb(221, 221, 221); box-sizing: inherit; color: #777777; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 17.5px; margin: 1.5em 0px; padding: 1em 0px 1em 1em;">
<div style="box-sizing: inherit; line-height: 1.9;">
注:デコードロジックは手動で記述することも、 <a href="https://app.quicktype.io/" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">QuickType</a> などのサービスを使用することもできます。 <br style="box-sizing: inherit;" />経験則として、私が所有するサービスについては、手作業で行います。 <br style="box-sizing: inherit;" />サードパーティサービスの場合、QuickTypeを使用してボイラープレートを生成します。 <br style="box-sizing: inherit;" />このプロジェクトでは、 Responses.swiftにこのサービスで生成されたエンティティがあります。</div>
</blockquote>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
次に、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeatherFetcher.swift</code>を開きます。このエンティティは、OpenWeatherMap APIから情報を取得し、データを解析してそのコンシューマーに提供します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
優れたSwift市民のように、プロトコルから始めます。インポートの下に次を追加します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeatherFetcher.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">protocol</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetchable</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">weeklyWeatherForecast</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="n" style="box-sizing: inherit;">forCity</span> <span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span>
<span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">-></span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyPublisher</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyForecastResponse</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherError</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">currentWeatherForecast</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="n" style="box-sizing: inherit;">forCity</span> <span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span>
<span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">-></span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyPublisher</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherForecastResponse</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherError</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
最初の画面で最初の方法を使用して、今後5日間の天気予報を表示します。 2番目を使用して、より詳細な天気情報を表示します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">AnyPublisher</code>とは何か、なぜAnyPublisherに2つの型パラメーターがあるのか疑問に思われるかもしれません。 これは、今後の計算、または購読すると実行される何かと考えることができます。 最初のパラメーター(<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyForecastResponse</code>)は、計算が成功した場合に返す型を参照し、ご想像のとおり、2番目は失敗した場合の型(<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeatherError</code>)を参照します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
クラス宣言の下に次のコードを追加して、これらの2つのメソッドを実装します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeatherFetcher.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="c1" style="box-sizing: inherit; color: #9dabae;">// MARK: - WeatherFetchable</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">extension</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetchable</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">weeklyWeatherForecast</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="n" style="box-sizing: inherit;">forCity</span> <span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span>
<span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">-></span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyPublisher</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyForecastResponse</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherError</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">forecast</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">with</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">makeWeeklyForecastComponents</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">withCity</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">))</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">currentWeatherForecast</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="n" style="box-sizing: inherit;">forCity</span> <span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span>
<span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">-></span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyPublisher</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherForecastResponse</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherError</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">forecast</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">with</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">makeCurrentDayForecastComponents</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">withCity</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">))</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">private</span> <span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="n" style="box-sizing: inherit;">forecast</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">T</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span><span class="p" style="box-sizing: inherit;">(</span>
<span class="n" style="box-sizing: inherit;">with</span> <span class="nv" style="box-sizing: inherit;">components</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">URLComponents</span>
<span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">-></span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyPublisher</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">T</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherError</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span> <span class="k" style="box-sizing: inherit; color: #ebd247;">where</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">T</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Decodable</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 1</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">guard</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">url</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">components</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">url</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">else</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">error</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherError</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">network</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">description</span><span class="p" style="box-sizing: inherit;">:</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">"Couldn't create URL"</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Fail</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">error</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">error</span><span class="p" style="box-sizing: inherit;">)</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">eraseToAnyPublisher</span><span class="p" style="box-sizing: inherit;">()</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 2</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="n" style="box-sizing: inherit;">session</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">dataTaskPublisher</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">for</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">URLRequest</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">url</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">url</span><span class="p" style="box-sizing: inherit;">))</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 3</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">mapError</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="n" style="box-sizing: inherit;">error</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">network</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">description</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">error</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">localizedDescription</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 4</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">flatMap</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">maxPublishers</span><span class="p" style="box-sizing: inherit;">:</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">max</span><span class="p" style="box-sizing: inherit;">(</span><span class="mi" style="box-sizing: inherit; color: #a980f5;">1</span><span class="p" style="box-sizing: inherit;">))</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="n" style="box-sizing: inherit;">pair</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="nf" style="box-sizing: inherit; color: #8bdf4c;">decode</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">pair</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">data</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 5</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">eraseToAnyPublisher</span><span class="p" style="box-sizing: inherit;">()</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
これが何をするかです:</div>
<ol style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">URLComponents</code>から<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">URL</code>のインスタンスを作成してみてください。 これが失敗した場合、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Fail</code>値にラップされたエラーを返します。 次に、その型を<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">AnyPublisher</code>に消去します。これがメソッドの戻り値型であるためです。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
新しい<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">URLSession</code>メソッド<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">dataTaskPublisher(for :)</code>を使用してデータを取得します。 このメソッドは<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">URLRequest</code>のインスタンスを受け取り、タプル<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">(Data、URLResponse)</code>または<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">URLError</code>を返します。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
メソッドは<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">AnyPublisher <t eathererror=""></t></code>を返すため、エラーを<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">URLError</code>から<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeatherError</code>にマッピングします。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">flatMap</code>の使用は、独自の投稿に値します。 ここでは、JSONとしてサーバーから送信されるデータを完全なオブジェクトに変換するために使用します。 これを実現するには、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">decode(_ :)</code>を補助関数として使用します。 ネットワークリクエストによって出力される最初の値のみに関心があるため、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">.max(1)</code>を設定します。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">eraseToAnyPublisher()</code>を使用しない場合、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">flatMap</code>によって返される完全なタイプを引き継ぐ必要があります:<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Publishers.FlatMap <anypublisher eathererror="">,Publishers.MapError <urlsession .datataskpublisher="" eathererror="">></urlsession></anypublisher></code>。 APIのコンシューマーとして、これらの詳細に悩まされることは望ましくありません。 したがって、APIの人間工学を改善するには、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">AnyPublisher</code>のタイプを消去します。 新しい変換(<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">filter</code>など)を追加すると、返される型が変更されるため、実装の詳細が明らかとなるため、これも便利です。</div>
</li>
</ol>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
モデルレベルでは、必要なものがすべて揃っているはずです。アプリをビルドして、すべてが機能することを確認します。</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="viewmodelsに飛び込む" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#viewmodels%E3%81%AB%E9%A3%9B%E3%81%B3%E8%BE%BC%E3%82%80" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>ViewModelsに飛び込む</h2>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
次に、週次予測画面を駆動するViewModelを作ります。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/8791d64f920d9aaa1932b4794140e0b0d1feb9b0/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f63383436303866322d323638632d363639342d313766382d6664313630613637653037312e676966" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="weekly_forecast.gif" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/c84608f2-268c-6694-17f8-fd160a67e071.gif" src="https://camo.qiitausercontent.com/8791d64f920d9aaa1932b4794140e0b0d1feb9b0/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f63383436303866322d323638632d363639342d313766382d6664313630613637653037312e676966" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<span style="box-sizing: inherit; font-weight: 700;">WeeklyWeatherViewModel.swift</span>を開き、以下を追加します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherViewModel.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">import</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">SwiftUI</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">import</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Combine</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 1</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">class</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyWeatherViewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">ObservableObject</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Identifiable</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 2</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">@Published</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">""</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 3</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">@Published</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">dataSource</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">[</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">DailyWeatherRowViewModel</span><span class="p" style="box-sizing: inherit;">]</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="p" style="box-sizing: inherit;">[]</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">private</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetchable</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 4</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">private</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">disposables</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Set</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyCancellable</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span><span class="p" style="box-sizing: inherit;">()</span>
<span class="nf" style="box-sizing: inherit; color: #8bdf4c;">init</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetchable</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">weatherFetcher</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">weatherFetcher</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
そのコードの機能は次のとおりです。</div>
<ol style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code>を<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">ObservableObject</code>および<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Identifiable</code>に準拠させます。 これらに準拠するということは、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code>のプロパティをバインディングとして使用できることを意味します。 ビューレイヤーに到達すると、作成方法が表示されます。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
適切にデリゲートされた<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">@Published</code>修飾子により、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">city</code>プロパティを監視することができます。 これを活用する方法がすぐにわかります。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
ビューのデータソースをViewModelに保持します。 これは、MVCで行うことに慣れている場合とは対照的です。 プロパティには<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">@Published</code>のマークが付けられているため、コンパイラーは自動的にパブリッシャーを合成します。 SwiftUIはそのパブリッシャーをサブスクライブし、プロパティを変更すると画面を再描画します。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">disposables</code>は、リクエストへの参照のコレクションと考えてください。 これらの参照を保持しないと、送信するネットワークリクエストは保持されず、サーバーからの応答を取得できなくなります。</div>
</li>
</ol>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
次に、イニシャライザの下に以下を追加して<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeatherFetcher</code>を使用します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherViewModel.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">fetchWeather</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">forCity</span> <span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 1</span>
<span class="n" style="box-sizing: inherit;">weatherFetcher</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">weeklyWeatherForecast</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">forCity</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">map</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="n" style="box-sizing: inherit;">response</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 2</span>
<span class="n" style="box-sizing: inherit;">response</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">list</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">map</span><span class="p" style="box-sizing: inherit;">(</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">DailyWeatherRowViewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="kd" style="box-sizing: inherit; color: #ebd247;">init</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 3</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">map</span><span class="p" style="box-sizing: inherit;">(</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">Array</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">removeDuplicates</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 4</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">receive</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">on</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">DispatchQueue</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">main</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 5</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">sink</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="nv" style="box-sizing: inherit;">receiveCompletion</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="p" style="box-sizing: inherit;">[</span><span class="k" style="box-sizing: inherit; color: #ebd247;">weak</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="p" style="box-sizing: inherit;">]</span> <span class="n" style="box-sizing: inherit;">value</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">guard</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">self</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">else</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">switch</span> <span class="n" style="box-sizing: inherit;">value</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">case</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nv" style="box-sizing: inherit;">failure</span><span class="p" style="box-sizing: inherit;">:</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 6</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dataSource</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="p" style="box-sizing: inherit;">[]</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">case</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nv" style="box-sizing: inherit;">finished</span><span class="p" style="box-sizing: inherit;">:</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">break</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">},</span>
<span class="nv" style="box-sizing: inherit;">receiveValue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="p" style="box-sizing: inherit;">[</span><span class="k" style="box-sizing: inherit; color: #ebd247;">weak</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="p" style="box-sizing: inherit;">]</span> <span class="n" style="box-sizing: inherit;">forecast</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">guard</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">self</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">else</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="p" style="box-sizing: inherit;">}</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 7</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dataSource</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">forecast</span>
<span class="p" style="box-sizing: inherit;">})</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 8</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">store</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">in</span><span class="p" style="box-sizing: inherit;">:</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">&</span><span class="n" style="box-sizing: inherit;">disposables</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
ここでは非常に多くのことが行われていますが、この後はすべてが簡単になると約束しています。</div>
<ol style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<a href="https://openweathermap.org/" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">OpenWeatherMap</a> APIから情報を取得する新しいリクエストを作成することから始めます。引数として都市名を渡します。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
レスポンス(<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyForecastResponse</code>オブジェクト)を<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">DailyWeatherRowViewModel</code>オブジェクトの配列にマップします。 このエンティティは、リスト内の単一の行を表します。 <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">DailyWeatherRowViewModel.swift</code>にある実装を確認できます。 MVVMでは、ViewModelレイヤーが必要なデータをViewに正確に公開することが最重要です。 View a <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyForecastResponse</code>に直接公開することは意味がありません。これにより、Viewレイヤーがモデルを消費するためにフォーマットするように強制されます。 ビューをできるだけダムにし、レンダリングのみに関係するようにすることをお勧めします。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<a href="https://openweathermap.org/" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">OpenWeatherMap</a> APIは、時刻に応じて同じ日の複数の温度を返すため、重複を削除します。 <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Array + Filtering.swift</code>をチェックして、その方法を確認できます。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
サーバーからのデータの取得、またはJSONのblobの解析はバックグラウンドキューで行われますが、UIの更新はメインキューで行われる必要があります。 <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">receive(on:)</code>を使用すると、ステップ5、6、および7で行う更新が適切な場所で行われるようになります。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">sink(receiveCompletion:receiveValue:)</code>を介してパブリッシャーを開始します。これは、それに応じてdataSourceを更新する場所です。成功または失敗した完了の処理は、値の処理とは別に発生することに注意することが重要です。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
障害が発生した場合、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">dataSource</code>を空の配列として設定します。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
新しい予報が到着したときに<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">dataSource</code>を更新します。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
最後に、キャンセル可能な参照を <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">disposables</code>セットに追加します。前述のように、この参照を有効にしないと、ネットワークパブリッシャーはすぐに終了します。</div>
</li>
</ol>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="週間天気図" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#%E9%80%B1%E9%96%93%E5%A4%A9%E6%B0%97%E5%9B%B3" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>週間天気図</h2>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<span style="box-sizing: inherit; font-weight: 700;">WeeklyWeatherView.swift</span>を開いて開始します。次に、viewModelプロパティと初期化子を構造体内に追加します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherView.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">@ObservedObject</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyWeatherViewModel</span>
<span class="nf" style="box-sizing: inherit; color: #8bdf4c;">init</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyWeatherViewModel</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">viewModel</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">viewModel</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">@ObservedObject</code>プロパティデリゲートは、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherView</code>と<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code>間の接続を確立します。 つまり、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherView</code>のプロパティ<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">objectWillChange</code>が値を送信すると、データソースが変更されようとしていることがビューに通知され、結果としてビューが再レンダリングされます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
次に、<span style="box-sizing: inherit; font-weight: 700;">SceneDelegate.swift</span>を開き、古い<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">weeklyView</code>プロパティを次のものに置き換えます。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">SceneDelegate.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">fetcher</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetcher</span><span class="p" style="box-sizing: inherit;">()</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">viewModel</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyWeatherViewModel</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">fetcher</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">weeklyView</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyWeatherView</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">)</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
プロジェクトを再度ビルドして、すべてがコンパイルされることを確認します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<span style="box-sizing: inherit; font-weight: 700;">WeeklyWeatherView.swift</span>に戻り、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">body</code>をアプリの実際の実装に置き換えます。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherView.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">body</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">NavigationView</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">List</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">searchField</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">if</span> <span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dataSource</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">isEmpty</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">emptySection</span>
<span class="p" style="box-sizing: inherit;">}</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">else</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">cityHourlyWeatherSection</span>
<span class="n" style="box-sizing: inherit;">forecastSection</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">listStyle</span><span class="p" style="box-sizing: inherit;">(</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">GroupedListStyle</span><span class="p" style="box-sizing: inherit;">())</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">navigationBarTitle</span><span class="p" style="box-sizing: inherit;">(</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"Weather ⛅️"</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">dataSource</code>が空の場合、空のセクションが表示されます。それ以外の場合は、予測セクションと、検索した特定の都市の詳細を表示する機能が表示されます。ファイルの下部に次を追加します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherView.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">private</span> <span class="kd" style="box-sizing: inherit; color: #ebd247;">extension</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyWeatherView</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">searchField</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">HStack</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">alignment</span><span class="p" style="box-sizing: inherit;">:</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">center</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 1</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">TextField</span><span class="p" style="box-sizing: inherit;">(</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"e.g. Cupertino"</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nv" style="box-sizing: inherit;">text</span><span class="p" style="box-sizing: inherit;">:</span> <span class="err" style="border-bottom: 2px dotted rgb(192, 27, 27); box-sizing: inherit; color: #dddddd;">$</span><span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">forecastSection</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">Section</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 2</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">ForEach</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dataSource</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nv" style="box-sizing: inherit;">content</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">DailyWeatherRow</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">init</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">:))</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">cityHourlyWeatherSection</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">Section</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">NavigationLink</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">destination</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherView</span><span class="p" style="box-sizing: inherit;">())</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">VStack</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">alignment</span><span class="p" style="box-sizing: inherit;">:</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">leading</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 3</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">Text</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">Text</span><span class="p" style="box-sizing: inherit;">(</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"Weather today"</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">font</span><span class="p" style="box-sizing: inherit;">(</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">caption</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">foregroundColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">gray</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">emptySection</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">Section</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">Text</span><span class="p" style="box-sizing: inherit;">(</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"No results"</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">foregroundColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">gray</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
ここにはかなりのコードがありますが、主な部分は3つだけです。</div>
<ol style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
最初のバインド! <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">$viewModel.city</code>は、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">TextField</code>に入力する値と<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code> の <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">city</code> プロパティの間の接続を確立します。 <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">$</code> を使用すると、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">city</code> プロパティを <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Binding<string></string></code> に変換できます。 これは、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code> が <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">ObservableObject</code> に準拠し、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">@ObservedObject</code>プロパティラッパーで宣言されているためにのみ可能です。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
独自のViewModelを使用して、毎日の天気予報の行を初期化します。 <span style="box-sizing: inherit; font-weight: 700;">DailyWeatherRow.swift</span>を開いて、動作を確認します。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
派手なバインドなしで、引き続き<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code>プロパティを使用してアクセスできます。これは、都市名を<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Text</code>で表示するだけです。</div>
</li>
</ol>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
アプリをビルドして実行すると、次のように表示されます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/ab64d80fc937747dc97204c9ca74e4826403c8bc/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f61326266656165612d663138362d366130342d623162652d3966616435333861373735362e706e67" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="Simulator-Screen-Shot-iPhone-8-2019-07-06-at-17.36.58.png" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/a2bfeaea-f186-6a04-b1be-9fad538a7756.png" src="https://camo.qiitausercontent.com/ab64d80fc937747dc97204c9ca74e4826403c8bc/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f61326266656165612d663138362d366130342d623162652d3966616435333861373735362e706e67" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" width="375" /></a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
驚いたことに、またはそうではなく、何も起こりません。 これは、実際のHTTPリクエストに<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">city</code>バインドをまだ接続していないためです。 それを修正しましょう。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<span style="box-sizing: inherit; font-weight: 700;">WeeklyWeatherViewModel.swift</span>を開き、現在の初期化子を次のものに置き換えます。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherViewModel.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="c1" style="box-sizing: inherit; color: #9dabae;">// 1</span>
<span class="nf" style="box-sizing: inherit; color: #8bdf4c;">init</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="nv" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetchable</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="nv" style="box-sizing: inherit;">scheduler</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">DispatchQueue</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">DispatchQueue</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">label</span><span class="p" style="box-sizing: inherit;">:</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">"WeatherViewModel"</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">weatherFetcher</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">weatherFetcher</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 2</span>
<span class="n" style="box-sizing: inherit;">_</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="err" style="border-bottom: 2px dotted rgb(192, 27, 27); box-sizing: inherit; color: #dddddd;">$</span><span class="n" style="box-sizing: inherit;">city</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 3</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">dropFirst</span><span class="p" style="box-sizing: inherit;">(</span><span class="mi" style="box-sizing: inherit; color: #a980f5;">1</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 4</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">debounce</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">for</span><span class="p" style="box-sizing: inherit;">:</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">seconds</span><span class="p" style="box-sizing: inherit;">(</span><span class="mf" style="box-sizing: inherit; color: #a980f5;">0.5</span><span class="p" style="box-sizing: inherit;">),</span> <span class="nv" style="box-sizing: inherit;">scheduler</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">scheduler</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 5</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">sink</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">receiveValue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">fetchWeather</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">forCity</span><span class="p" style="box-sizing: inherit;">:))</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
このコードは、SwiftUIとCombineの両方の世界をつなぐため、非常に重要です。</div>
<ol style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">scheduler</code>パラメータを追加して、HTTPリクエストが使用するキューを指定できるようにします。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">city</code>プロパティは<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">@Published</code>プロパティデリゲートを使用するため、他の<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Publisher</code>と同様に機能します。 これは、それが観察可能であり、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Publisher</code>で利用可能な他の方法も利用できることを意味します。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
観測値を作成するとすぐに、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">$city</code>は最初の値を出力します。 最初の値は空の文字列であるため、意図しないネットワーク呼び出しを避けるためにそれをスキップする必要があります。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">debounce(for:scheduler:)</code>を使用して、ユーザー体験を向上させます。 これがないと、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">fetchWeather</code>は入力されたすべての文字に対して新しいHTTP要求を作成します。 デバウンスは、ユーザーが入力を停止して最終的に値を送信するまで0.5秒待機することで機能します。 <a href="https://rxmarbles.com/#debounce" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">RxMarbles</a>でこの動作の優れた視覚化を見つけることができます。 また、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">scheduler</code>を引数として渡します。つまり、発行される値はその特定のキューに置かれます。 経験則:バックグラウンドキューで値を処理し、メインキューで配信する必要があります。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
最後に、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">sink(receiveValue:)</code>を介してこれらのイベントを観察し、以前に実装した<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">fetchWeather(forCity:)</code>でそれらを処理します。</div>
</li>
</ol>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
プロジェクトをビルドして実行します。最終的にメイン画面が動作しているのが見えるはずです。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/fb98442444bd13bf0815058e60de85b3adf0e422/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f39643037663562612d343663312d356361342d656664312d3531326539353630386331322e676966" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="weekly_forecast (1).gif" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/9d07f5ba-46c1-5ca4-efd1-512e95608c12.gif" src="https://camo.qiitausercontent.com/fb98442444bd13bf0815058e60de85b3adf0e422/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f39643037663562612d343663312d356361342d656664312d3531326539353630386331322e676966" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="ナビゲーションと現在の天気画面" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#%E3%83%8A%E3%83%93%E3%82%B2%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%A8%E7%8F%BE%E5%9C%A8%E3%81%AE%E5%A4%A9%E6%B0%97%E7%94%BB%E9%9D%A2" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>ナビゲーションと現在の天気画面</h2>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
アーキテクチャパターンとしてのMVVMは、細かい点には触れません。 一部の決定は、開発者の裁量に任されています。 それらの1つは、ある画面から別の画面にナビゲートする方法、およびその責任を所<br style="box-sizing: inherit;" />有するエンティティです。 SwiftUIは、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">NavigationLink</code>の使用に関するヒントを提供するため、このチュートリアルではこれを使用します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">NavigationLink</code>の最も基本的なイニシャライザーである<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">public init<v>(destination:V、label: () -> Label)where V:View</v></code>を見ると、引数として<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">View</code>を期待していることがわかります。 これは、本質的に、現在のビュー(起点)を別のビュー(終点)に結び付けます。 この関係は、よりシンプルなアプリでは問題ないかもしれませんが、外部ロジック(サーバー応答など)に基づいて異なる宛先を必要とする複雑なフローがある場合、問題が発生する可能性があります。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
MVVMレシピに従って、ViewはViewModelに次に何をするかを尋ねる必要がありますが、予想されるパラメーターはViewであり、ViewModelはこれらの懸念を認識しないため、これは注意が必要です。 この問題は、アプリケーション全体のルーティングを管理するためにViewModelと共に動作する,さらに別のエンティティによって表されるFlowControllersまたはCoordinatorsを介して解決されます。 このアプローチはうまく拡張できますが、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">NavigationLink</code>のようなものを使用するのを妨げるでしょう。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
これらはすべてこのチュートリアルの範囲外であるため、ここでは実用的であり、ハイブリッドアプローチを使用します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
ナビゲーションに進む前に、まず<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">CurrentWeatherView</code>と<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">CurrentWeatherViewModel</code>を更新します。 <span style="box-sizing: inherit; font-weight: 700;">CurrentWeatherViewModel.swift</span>を開き、次を追加します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">CurrentWeatherViewModel.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">import</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">SwiftUI</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">import</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Combine</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 1</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">class</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherViewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">ObservableObject</span><span class="p" style="box-sizing: inherit;">,</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Identifiable</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 2</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">@Published</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">dataSource</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherRowViewModel</span><span class="p" style="box-sizing: inherit;">?</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">private</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetchable</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">private</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">disposables</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">Set</span><span class="o" style="box-sizing: inherit; color: #ff8095;"><</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyCancellable</span><span class="o" style="box-sizing: inherit; color: #ff8095;">></span><span class="p" style="box-sizing: inherit;">()</span>
<span class="nf" style="box-sizing: inherit; color: #8bdf4c;">init</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nv" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetchable</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">weatherFetcher</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">weatherFetcher</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">city</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">city</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">refresh</span><span class="p" style="box-sizing: inherit;">()</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">weatherFetcher</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">currentWeatherForecast</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">forCity</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 3</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">map</span><span class="p" style="box-sizing: inherit;">(</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherRowViewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="kd" style="box-sizing: inherit; color: #ebd247;">init</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">receive</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">on</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">DispatchQueue</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">main</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">sink</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">receiveCompletion</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="p" style="box-sizing: inherit;">[</span><span class="k" style="box-sizing: inherit; color: #ebd247;">weak</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="p" style="box-sizing: inherit;">]</span> <span class="n" style="box-sizing: inherit;">value</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">guard</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">self</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">else</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">switch</span> <span class="n" style="box-sizing: inherit;">value</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">case</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nv" style="box-sizing: inherit;">failure</span><span class="p" style="box-sizing: inherit;">:</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dataSource</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kc" style="box-sizing: inherit; color: #ebd247;">nil</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">case</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nv" style="box-sizing: inherit;">finished</span><span class="p" style="box-sizing: inherit;">:</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">break</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">},</span> <span class="nv" style="box-sizing: inherit;">receiveValue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="p" style="box-sizing: inherit;">[</span><span class="k" style="box-sizing: inherit; color: #ebd247;">weak</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="p" style="box-sizing: inherit;">]</span> <span class="n" style="box-sizing: inherit;">weather</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">guard</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">self</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">else</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dataSource</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">weather</span>
<span class="p" style="box-sizing: inherit;">})</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">store</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">in</span><span class="p" style="box-sizing: inherit;">:</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">&</span><span class="n" style="box-sizing: inherit;">disposables</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">CurrentWeatherViewModel</code>は、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code>で以前に行ったことを模倣します。</div>
<ol style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;"><code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">CurrentWeatherViewModel</code>を<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">ObservableObject</code>および<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Identifiable</code>に準拠させます。</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
オプションの<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">CurrentWeatherRowViewModel</code>をデータソースとして公開します。</div>
</li>
<li style="box-sizing: inherit;"><div style="box-sizing: inherit; line-height: 1.9; margin-bottom: 1em; margin-top: 1em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">CurrentWeatherForecastResponse</code>の形式で新しい値を<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">CurrentWeatherRowViewModel</code>に変換します。</div>
</li>
</ol>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
次に、UIです。 <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">CurrentWeatherView.swift</code>を開き、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">struct</code>の上部に初期化子を追加します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">CurrentWeatherView.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">@ObservedObject</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherViewModel</span>
<span class="nf" style="box-sizing: inherit; color: #8bdf4c;">init</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherViewModel</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">viewModel</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">viewModel</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
これは、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherView</code>で適用したのと同じパターンに従います。おそらく、独自のプロジェクトでSwiftUIを使用するときに実行することです。ViewにViewModelを挿入し、そのパブリックAPIにアクセスします。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
ここで、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">body</code> のcomputed propertyを更新します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">CurrentWeatherView.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">body</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">List</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">content</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">content</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">onAppear</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">perform</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">refresh</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">navigationBarTitle</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">listStyle</span><span class="p" style="box-sizing: inherit;">(</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">GroupedListStyle</span><span class="p" style="box-sizing: inherit;">())</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">onAppear(perform:)</code>メソッドの使用に気付くでしょう。 これは、type <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">() -> Void</code>の関数を取り、ビューが表示されたときに実行します。 この場合、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">dataSource</code>を更新できるように、ViewModelで<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">refresh()</code>を呼び出します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
最後に、ファイルの最後に次を追加します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">CurrentWeatherView.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">private</span> <span class="kd" style="box-sizing: inherit; color: #ebd247;">extension</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherView</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">content</span><span class="p" style="box-sizing: inherit;">()</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">-></span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">if</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">viewModel</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dataSource</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyView</span><span class="p" style="box-sizing: inherit;">(</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">details</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">for</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">))</span>
<span class="p" style="box-sizing: inherit;">}</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">else</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">AnyView</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">loading</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">details</span><span class="p" style="box-sizing: inherit;">(</span><span class="k" style="box-sizing: inherit; color: #ebd247;">for</span> <span class="nv" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherRowViewModel</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">-></span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherRow</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">loading</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">Text</span><span class="p" style="box-sizing: inherit;">(</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"Loading </span><span class="se" style="box-sizing: inherit; color: #a980f5;">\(</span><span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">city</span><span class="se" style="box-sizing: inherit; color: #a980f5;">)</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">'s weather..."</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">foregroundColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">gray</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
これにより、残りのUIが少し追加されます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">CurrentWeatherView</code>イニシャライザを変更したため、プロジェクトはまだコンパイルされていません。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
ほとんどの部分が揃ったので、次はナビゲーションをまとめましょう。 <span style="box-sizing: inherit; font-weight: 700;">WeeklyWeatherBuilder.swift</span>を開き、次を追加します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherBuilder.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">import</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">SwiftUI</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">enum</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyWeatherBuilder</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kd" style="box-sizing: inherit; color: #ebd247;">static</span> <span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">makeCurrentWeatherView</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="n" style="box-sizing: inherit;">withCity</span> <span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="nv" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeatherFetchable</span>
<span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">-></span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">viewModel</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherViewModel</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="nv" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">CurrentWeatherView</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">viewModel</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
このエンティティは、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherView</code>からナビゲートするときに必要な画面を作成するファクトリーとして機能します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<span style="box-sizing: inherit; font-weight: 700;">WeeklyWeatherViewModel.swift</span>を開き、ファイルの下部に以下を追加してビルダーの使用を開始します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherViewModel.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">extension</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyWeatherViewModel</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">currentWeatherView</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">some</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">View</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">WeeklyWeatherBuilder</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">makeCurrentWeatherView</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="nv" style="box-sizing: inherit;">withCity</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="nv" style="box-sizing: inherit;">weatherFetcher</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">weatherFetcher</span>
<span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
最後に、<span style="box-sizing: inherit; font-weight: 700;">WeeklyWeatherView.swift</span>を開き、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">cityHourlyWeatherSection</code>プロパティの実装を次のように変更します。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
ここで重要なのは、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">viewModel.currentWeatherView</code>です。 <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherView</code>は、次に表示するビューを<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code>に尋ねます。 <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code>は、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherBuilder</code>を使用して必要なビューを提供します。 責任の間に良い分離があり、同時にそれらの間の全体的な関係を容易に追跡できます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
ナビゲーションの問題を解決する方法は他にもたくさんあります。 一部の開発者は、Viewレイヤーがナビゲートする場所や、ナビゲーションがどのように発生するか(モーダルまたはプッシュ)を認識すべきではないと主張します。 それが議論である場合、Appleが<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">NavigationLink</code>で提供しているものを使用することはもはや意味がありません。 プラグマティズムとスケーラビリティのバランスをとることが重要です。 このチュートリアルは前者に傾いています。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
プロジェクトをビルドして実行します。 すべてが期待どおりに動作するはずです! 天気アプリの作成おめでとうございます! :]</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/5b23f07b09e8adae53cd7d72e6b4284a65fe5c31/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f32313261343863322d386433642d343665322d326334652d3264306331353031666236372e676966" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="weather_final-1 (1).gif" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/212a48c2-8d3d-46e2-2c4e-2d0c1501fb67.gif" src="https://camo.qiitausercontent.com/5b23f07b09e8adae53cd7d72e6b4284a65fe5c31/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f32313261343863322d386433642d343665322d326334652d3264306331353031666236372e676966" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="追加でナビゲーションタイトルを更新してみる" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#%E8%BF%BD%E5%8A%A0%E3%81%A7%E3%83%8A%E3%83%93%E3%82%B2%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB%E3%82%92%E6%9B%B4%E6%96%B0%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>追加でナビゲーションタイトルを更新してみる</h2>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
ここまでがチュートリアルの内容でしたが、簡単な機能を追加してみることにします。</div>
<ul style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;">入力した <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">city</code> の今日の天気に応じて絵文字 雨☔, 曇り🌥, 晴れ☀️を表示</li>
<li style="box-sizing: inherit;">週間天気にも絵文字を表示し視覚的にわかりやすく</li>
</ul>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
やはりViewModelからいきます。<br style="box-sizing: inherit;" /><span style="box-sizing: inherit; font-weight: 700;">DailyWeatherRowViewModel.swift</span> に以下のプロパティを追加</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">DailyWeatherRowViewModel.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"> <span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">emoji</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">switch</span> <span class="n" style="box-sizing: inherit;">item</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">weather</span><span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: #a980f5;">0</span><span class="p" style="box-sizing: inherit;">]</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">main</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">case</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nv" style="box-sizing: inherit;">clear</span><span class="p" style="box-sizing: inherit;">:</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">"☀️"</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">case</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nv" style="box-sizing: inherit;">clouds</span><span class="p" style="box-sizing: inherit;">:</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">"🌥"</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">case</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nv" style="box-sizing: inherit;">rain</span><span class="p" style="box-sizing: inherit;">:</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">"☔️"</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
週間天気の一行目の天気の列挙体に合わせて、絵文字をマッピングします。<br style="box-sizing: inherit;" />タイムゾーンなどは考慮していません。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
次に<span style="box-sizing: inherit; font-weight: 700;">WeeklyWeatherViewModel.swift</span>を編集します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherViewModel.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kd" style="box-sizing: inherit; color: #ebd247;">@Published</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">var</span> <span class="nv" style="box-sizing: inherit;">todaysWeatherEmoji</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">""</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">Published</code>修飾子の<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">todaysWeatherEmoji</code>を絵文字表示用に定義し、<br style="box-sizing: inherit;" />値の変更を監視します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherViewModel.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"> <span class="kd" style="box-sizing: inherit; color: #ebd247;">func</span> <span class="nf" style="box-sizing: inherit; color: #8bdf4c;">fetchWeather</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">forCity</span> <span class="nv" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">String</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">weatherFetcher</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">weeklyWeatherForecast</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">forCity</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">city</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">map</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="n" style="box-sizing: inherit;">response</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="n" style="box-sizing: inherit;">response</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">list</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">map</span><span class="p" style="box-sizing: inherit;">(</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">DailyWeatherRowViewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="kd" style="box-sizing: inherit; color: #ebd247;">init</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">map</span><span class="p" style="box-sizing: inherit;">(</span><span class="kt" style="box-sizing: inherit; color: #ebd247;">Array</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">removeDuplicates</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">receive</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">on</span><span class="p" style="box-sizing: inherit;">:</span> <span class="kt" style="box-sizing: inherit; color: #ebd247;">DispatchQueue</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">main</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">sink</span><span class="p" style="box-sizing: inherit;">(</span>
<span class="nv" style="box-sizing: inherit;">receiveCompletion</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="p" style="box-sizing: inherit;">[</span><span class="k" style="box-sizing: inherit; color: #ebd247;">weak</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="p" style="box-sizing: inherit;">]</span> <span class="n" style="box-sizing: inherit;">value</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">guard</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">self</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">else</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">switch</span> <span class="n" style="box-sizing: inherit;">value</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">case</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nv" style="box-sizing: inherit;">failure</span><span class="p" style="box-sizing: inherit;">:</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dataSource</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="p" style="box-sizing: inherit;">[]</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 1</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">todaysWeatherEmoji</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">""</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">case</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nv" style="box-sizing: inherit;">finished</span><span class="p" style="box-sizing: inherit;">:</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">break</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="p" style="box-sizing: inherit;">},</span>
<span class="nv" style="box-sizing: inherit;">receiveValue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="p" style="box-sizing: inherit;">[</span><span class="k" style="box-sizing: inherit; color: #ebd247;">weak</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="p" style="box-sizing: inherit;">]</span> <span class="n" style="box-sizing: inherit;">forecast</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">in</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">guard</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">let</span> <span class="nv" style="box-sizing: inherit;">self</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">self</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">else</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="k" style="box-sizing: inherit; color: #ebd247;">return</span> <span class="p" style="box-sizing: inherit;">}</span>
<span class="c1" style="box-sizing: inherit; color: #9dabae;">// 2</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">todaysWeatherEmoji</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">forecast</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">first</span><span class="p" style="box-sizing: inherit;">?</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">emoji</span> <span class="p" style="box-sizing: inherit;">??</span> <span class="s" style="box-sizing: inherit; color: #41b7d7;">""</span>
<span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">dataSource</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">=</span> <span class="n" style="box-sizing: inherit;">forecast</span>
<span class="p" style="box-sizing: inherit;">})</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">store</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">in</span><span class="p" style="box-sizing: inherit;">:</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">&</span><span class="n" style="box-sizing: inherit;">disposables</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<ol style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; list-style-image: initial; list-style-position: initial; margin: 1.5em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit;">エラー発生時は空を代入します。</li>
<li style="box-sizing: inherit;">流れてきた週間天気表示用の配列から <code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">forecast.first?.emoji</code> を代入します。</li>
</ol>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
最後に2点変更して終了です。<br style="box-sizing: inherit;" /><span style="box-sizing: inherit; font-weight: 700;">WeeklyWeatherView.swift</span>を編集</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">WeeklyWeatherView.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">navigationBarTitle</span><span class="p" style="box-sizing: inherit;">(</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"Weather </span><span class="se" style="box-sizing: inherit; color: #a980f5;">\(</span><span class="k" style="box-sizing: inherit; color: #ebd247;">self</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">todaysWeatherEmoji</span><span class="se" style="box-sizing: inherit; color: #a980f5;">)</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"</span><span class="p" style="box-sizing: inherit;">)</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">city</code>の変更に応じて、<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">WeeklyWeatherViewModel</code>の<code style="background-color: #eeeeee; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; padding: 0.1em 0.4em;">todaysWeatherEmoji</code>の更新がかかり、ナビゲーションバーのタイトルが更新されます。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
以下、<span style="box-sizing: inherit; font-weight: 700;">DailyWeatherRow.swift</span> にてタイトルに絵文字を連結させます。</div>
<div class="code-frame" data-lang="swift" style="background-color: #364549; box-sizing: inherit; color: #e3e3e3; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 0.9em; margin: 1.5em -32px; padding: 1em 32px;">
<div class="code-lang" style="background-color: #777777; box-sizing: inherit; color: #eeeeee; display: inline-block; padding: 2px 4px; transform: translateY(-1em); word-break: break-all;">
<span class="bold" style="box-sizing: inherit;">DailyWeatherRow.swift</span></div>
<div class="highlight" style="box-sizing: inherit; overflow-x: auto; padding: 0.5em;">
<pre style="background-color: transparent; border-radius: 0px; border: none; box-sizing: inherit; color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: inherit; line-height: 1.8; overflow-wrap: break-word; padding: 0px; word-break: break-all;"><span class="kt" style="box-sizing: inherit; color: #ebd247;">VStack</span><span class="p" style="box-sizing: inherit;">(</span><span class="nv" style="box-sizing: inherit;">alignment</span><span class="p" style="box-sizing: inherit;">:</span> <span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">leading</span><span class="p" style="box-sizing: inherit;">)</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">Text</span><span class="p" style="box-sizing: inherit;">(</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"</span><span class="se" style="box-sizing: inherit; color: #a980f5;">\(</span><span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">title</span><span class="se" style="box-sizing: inherit; color: #a980f5;">)</span><span class="s" style="box-sizing: inherit; color: #41b7d7;"> </span><span class="se" style="box-sizing: inherit; color: #a980f5;">\(</span><span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">emoji</span><span class="se" style="box-sizing: inherit; color: #a980f5;">)</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">font</span><span class="p" style="box-sizing: inherit;">(</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">body</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="kt" style="box-sizing: inherit; color: #ebd247;">Text</span><span class="p" style="box-sizing: inherit;">(</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"</span><span class="se" style="box-sizing: inherit; color: #a980f5;">\(</span><span class="n" style="box-sizing: inherit;">viewModel</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">fullDescription</span><span class="se" style="box-sizing: inherit; color: #a980f5;">)</span><span class="s" style="box-sizing: inherit; color: #41b7d7;">"</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">font</span><span class="p" style="box-sizing: inherit;">(</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">footnote</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="nf" style="box-sizing: inherit; color: #8bdf4c;">padding</span><span class="p" style="box-sizing: inherit;">(</span><span class="o" style="box-sizing: inherit; color: #ff8095;">.</span><span class="n" style="box-sizing: inherit;">leading</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: #a980f5;">8</span><span class="p" style="box-sizing: inherit;">)</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
Finish!<br style="box-sizing: inherit;" />ここまでのコードは<a href="https://github.com/manchan/MVVM-with-Combine-Tutorial-for-iOS" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank">こちら</a></div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
<a href="https://camo.qiitausercontent.com/676d32a62e86e390377d92ec666d520c7eb0715b/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f64646462643864662d636638322d646666352d316130312d3362396338663336616263392e676966" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;" target="_blank"><img alt="画面収録 2019-09-23 午前10.17.56.2019-09-23 10_23_19 AM.gif" data-canonical-src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/8972/dddbd8df-cf82-dff5-1a01-3b9c8f36abc9.gif" src="https://camo.qiitausercontent.com/676d32a62e86e390377d92ec666d520c7eb0715b/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f383937322f64646462643864662d636638322d646666352d316130312d3362396338663336616263392e676966" style="border-style: none; box-sizing: inherit; margin: 1.5em 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(221, 221, 221); box-sizing: inherit; color: #333333; cursor: pointer; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-feature-settings: "palt"; font-size: 1.6em; line-height: 1.5; margin: 2.2em 0px 2.4rem; padding-bottom: 0.1em; position: relative;">
<span class="fragment" id="ここからどこへ行きますか" style="box-sizing: inherit; display: block; position: relative; top: -1.5em;"></span><a href="https://qiita.com/you_matz/items/a3d640be2a8feaf698bd#%E3%81%93%E3%81%93%E3%81%8B%E3%82%89%E3%81%A9%E3%81%93%E3%81%B8%E8%A1%8C%E3%81%8D%E3%81%BE%E3%81%99%E3%81%8B" style="background-color: transparent; box-sizing: inherit; color: #6200ac; text-decoration-line: none;"></a>ここからどこへ行きますか?</h2>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9;">
このチュートリアルでは、MVVM、Combine、およびSwiftを使用して多くのことを説明しました。 これらのトピックはそれぞれチュートリアルであり、今日のゴールは、あなたが新しいことをはじめ、iOS開発の未来を垣間見ることでした。個人的な見解としては,AppleがFRPを正式にサポートした以上、新規のiOSアプリで中規模以上のものに関してはSwiftUI×Combineを使うことを強くおすすめします。</div>
<div style="background-color: white; box-sizing: inherit; color: #333333; font-family: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16px; line-height: 1.9; margin-top: 1.5em;">
ぜひ、このMVVMとCombineチュートリアルをお楽しみください。 ご質問やご意見がありましたら、以下コメント欄に投稿してください。</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-54302533765746681502018-12-31T12:39:00.001+09:002018-12-31T12:42:17.502+09:002018 Best Moments on Instagram今年はカメラにハマりにハマりました。<br />
本業のアプリ開発も順調にやっています。<br /><br />
Instagramはこちら↓<br />
<a href="https://www.instagram.com/you_matz/">https://www.instagram.com/you_matz/</a><br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJhhnYfTgDOoe-gBt-Rw-oTtOr98sw_YcDiG_xgFRC5_fkY1jRcR-VuJCqxWO94ORnbnXdrRok6gbYqrxmS-_TinMrsFR2C0dAmB4PBfQBqMsd-fgJ50N8hC4-CMCaa58JVK3ZGWly5iQ/s1600/2018-Best-Nine-Posts-for-Story.jpg" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJhhnYfTgDOoe-gBt-Rw-oTtOr98sw_YcDiG_xgFRC5_fkY1jRcR-VuJCqxWO94ORnbnXdrRok6gbYqrxmS-_TinMrsFR2C0dAmB4PBfQBqMsd-fgJ50N8hC4-CMCaa58JVK3ZGWly5iQ/s1600/2018-Best-Nine-Posts-for-Story.jpg" /></a><br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dyBdxHSVOonn4MjhpeI5eZvJ8U5Z4gXZeMwyjiJ-FYucdH5gZ8O2z1vsMbrkpMp3VtrZOwYZKFfvpbrpkYcjg' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div>
<br />you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-25218891118759761182017-08-05T14:31:00.003+09:002017-10-31T14:57:43.023+09:00iOSアプリ開発講座開催中<div class="SA-Widget">
今年になって新たな試みとして、人にアプリ開発やプログラミングを教えることを行っています。<br />
<br />
ひとりでもアプリ開発に興味を持っていただける方が増えたらよいなという気持ちで開催に至りました。<br />
普段使っているスマートフォンや身の回りのものはほとんどがソフトウェアで動いています。<br />
何でもネットに繋がる時代で、この動きはますます進むことは間違いありません。<br />
2020年に小学校からプログラミング教育必修化となったことも社会的に需要が増えていることを表しています。<br />
どんな動機でもプログラミングを学ぶことはこれからの社会にとって有益なことは間違いありません。一緒にアイディアを形にできれば、夢が広がるでしょう。<br />
<br />
まず初回はヒアリング、相談ベースからはじめたいと思います。<br />
ご気軽にどうぞ。<br />
<br />
<a class="sa-site-link" href="https://www.street-academy.com/?conversion_name=blog_parts&class_detail_id=18006&tracking_code=8bc81e9b1ceaad00a4fa1ab5260a64b2">STREET ACADEMY</a><a class="sa-site-link" href="https://www.street-academy.com/?conversion_name=blog_parts&class_detail_id=18006&tracking_code=8bc81e9b1ceaad00a4fa1ab5260a64b2">
</a>
<br />
<div id="SA-Widget-18006">
</div>
</div>
<script>
(function() {
var s = document.createElement("script");
s.src ="https://www.street-academy.com/javascripts/view/blog_parts/embed.js";
s.async = true;
s.charset = "utf-8";
window.sa_class_options = (window.sa_class_options || []).concat({id: 18006, type: 1, urlHost: "https://www.street-academy.com", trackingCode: "8bc81e9b1ceaad00a4fa1ab5260a64b2"});
document.body.appendChild(s);
})();
</script>you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-67676886497766449442017-02-05T21:33:00.000+09:002017-05-03T21:12:03.883+09:00JINS原宿店にてJINS MEME × Philips Hueが展示されています<div style="background-color: white; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
<div style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
JINS MEME旗艦店の原宿店にて、<br />
JINS MEMEと連携するIoTガジェットなどを体験出来るエリアがあり、<br />
開発したJINS MEME × Philips Hueが展示されています。<br />
JINS MEMEで照明を操作したデモアプリです。<br />
このデモはシンプルでわかりやすいので来訪者に人気なようです。</div>
<div style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/5ddc275e-de11-f818-b102-9caae0b54090.jpeg" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank"><img alt="HUE04.jpg" src="https://qiita-image-store.s3.amazonaws.com/0/8972/5ddc275e-de11-f818-b102-9caae0b54090.jpeg" style="border-style: none; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a><br />
メガネをつけた状態で瞬きや視線移動をするとライトが反応します。</div>
<div style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/b0b9284d-dbdf-b765-6c5b-cb3fe5eeda0f.jpeg" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank"><img alt="003.JPG" src="https://qiita-image-store.s3.amazonaws.com/0/8972/b0b9284d-dbdf-b765-6c5b-cb3fe5eeda0f.jpeg" style="border-style: none; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/d52e5617-4ca6-848a-b4bc-0991e10a7ec9.jpeg" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank"><img alt="005.JPG" src="https://qiita-image-store.s3.amazonaws.com/0/8972/d52e5617-4ca6-848a-b4bc-0991e10a7ec9.jpeg" style="border-style: none; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a><br />
紹介いただいています。</div>
<div style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
デモのアプリの中にはJINS MEMEを装着した状態でできる姿勢監視の機能も入っています。</div>
<div style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
また昨年(2016年12月)はJINS MEMEで照明を操作したこのデモがワールドビジネスサテライト(東テレ)に放映されました。</div>
<div class="SandboxRoot env-bp-350" data-twitter-event-id="0" style="background: 0px 0px; color: #1c2022; direction: ltr; font-family: Helvetica, Roboto, "Segoe UI", Calibri, sans-serif; font-size: 16px; font-stretch: normal; line-height: 1.4; position: relative; white-space: initial;">
<div class="EmbeddedTweet EmbeddedTweet--mediaForward media-forward js-clickToOpenTarget js-tweetIdInfo" data-click-to-open-target="https://twitter.com/wbs_tvtokyo/status/809375883676876801" data-dt-abbr="%{number}%{symbol}" data-dt-am="AM" data-dt-full="%{year}年%{month}%{day}日 %{hours24}:%{minutes}" data-dt-h="時間" data-dt-hour="時間" data-dt-hours="時間" data-dt-long="%{year}年%{month}%{day}日" data-dt-m="分" data-dt-minute="分" data-dt-minutes="分" data-dt-months="1月|2月|3月|4月|5月|6月|7月|8月|9月|10月|11月|12月" data-dt-now="今" data-dt-pm="PM" data-dt-s="秒" data-dt-second="秒" data-dt-seconds="秒" data-dt-short="%{month}%{day}日" data-iframe-title="Twitterツイート" data-scribe="page:tweet" data-tweet-id="809375883676876801" data-twitter-event-id="1" id="twitter-widget-0" lang="ja" style="border-radius: 4px; border: 0px; cursor: pointer; max-width: 520px; overflow: hidden;">
<br />
<br />
<article class="MediaCard
MediaCard--mediaForward
customisable-border" data-scribe="component:card" dir="ltr"><div class="MediaCard-mediaContainer js-cspForcedStyle" data-style="padding-bottom: 50%" style="background-color: #f5f8fa; padding-bottom: 250px; position: relative;">
<a class="MediaCard-borderOverlay" href="https://twitter.com/wbs_tvtokyo/status/809375883676876801/photo/1" role="presentation" style="background-color: transparent; border-radius: 4px 4px 0px 0px; border: 1px solid rgba(225, 232, 237, 0.74902); box-sizing: border-box; color: #2b7bb9; height: 250px; left: 0px; outline: 0px; position: absolute; text-decoration: none; top: 0px; width: 500px; z-index: 10;" tabindex="-1" title=""><span class="u-hiddenVisually" style="border: 0px !important; clip: rect(1px 1px 1px 1px) !important; height: 1px !important; overflow: hidden !important; padding: 0px !important; position: absolute !important; width: 1px !important;"></span></a><br />
<div class="MediaCard-mediaAsset
ImageGrid
ImageGrid--3
ImageGrid--roundedTop
" style="background-color: white; height: 250px; left: 0px; line-height: 0; position: absolute; top: 0px; transition: opacity 0.5s; width: 500px;">
<a class="ImageGrid-image
ImageGrid-image-0
CroppedImage
CroppedImage--fillHeight" href="https://twitter.com/wbs_tvtokyo/status/809375883676876801/photo/1" style="background-color: transparent; border-top-left-radius: 4px; border: 0px solid rgb(225, 232, 237); color: #2b7bb9; display: inline-block; float: left; left: 0px; outline: 0px; overflow: hidden; padding-bottom: 250px; position: absolute; text-decoration: none; top: 0px; transform: rotate(0deg); width: 250px;"><img alt="Twitterで画像を見る" class="CroppedImage-image js-cspForcedStyle" data-srcset="https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FCzt7BJxUAAAHmuI.jpg%3Alarge 1920w,https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FCzt7BJxUAAAHmuI.jpg 1200w,https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FCzt7BJxUAAAHmuI.jpg%3Asmall 680w" data-style="left:-37%;
;" height="675" src="https://pbs.twimg.com/media/Czt7BJxUAAAHmuI.jpg:small" style="border: 0px; height: 250px; left: -92.5px; min-height: 100%; min-width: 100%; position: absolute; top: 0px; width: auto;" title="Twitterで画像を見る" width="1200" /></a><a class="ImageGrid-image
ImageGrid-image-1
CroppedImage
CroppedImage--fillWidth
" href="https://twitter.com/wbs_tvtokyo/status/809375883676876801/photo/1" style="background-color: transparent; border-color: rgb(225, 232, 237); border-image: initial; border-style: solid; border-top-right-radius: 4px; border-width: 0px 0px 0px 1px; color: #2b7bb9; display: inline-block; outline: 0px; overflow: hidden; padding-bottom: 125px; position: absolute; right: 0px; text-decoration: none; top: 0px; transform: rotate(0deg); width: 250px;"><img alt="Twitterで画像を見る" class="CroppedImage-image js-cspForcedStyle" data-srcset="https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FCzt7CCJVEAA9Xfg.jpg%3Alarge 1920w,https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FCzt7CCJVEAA9Xfg.jpg 1200w,https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FCzt7CCJVEAA9Xfg.jpg%3Asmall 680w" data-style=";
top:-5%;" height="675" src="https://pbs.twimg.com/media/Czt7CCJVEAA9Xfg.jpg:small" style="border: 0px; height: auto; left: 0px; min-height: 100%; min-width: 100%; position: absolute; top: -6.25px; width: 250px;" title="Twitterで画像を見る" width="1200" /></a><a class="ImageGrid-image
ImageGrid-image-2
CroppedImage
CroppedImage--fillWidth
" href="https://twitter.com/wbs_tvtokyo/status/809375883676876801/photo/1" style="background-color: transparent; border-color: rgb(225, 232, 237); border-image: initial; border-style: solid; border-width: 1px 0px 0px 1px; bottom: 0px; color: #2b7bb9; display: inline-block; outline: 0px; overflow: hidden; padding-bottom: 125px; position: absolute; right: 0px; text-decoration: none; transform: rotate(0deg); width: 250px;"><img alt="Twitterで画像を見る" class="CroppedImage-image js-cspForcedStyle" data-srcset="https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FCzt7C38UUAAqVK2.jpg%3Alarge 1920w,https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FCzt7C38UUAAqVK2.jpg 1200w,https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FCzt7C38UUAAqVK2.jpg%3Asmall 680w" height="675" src="https://pbs.twimg.com/media/Czt7C38UUAAqVK2.jpg:small" style="border: 0px; height: auto; left: 0px; min-height: 100%; min-width: 100%; position: absolute; top: 0px; width: 250px;" title="Twitterで画像を見る" width="1200" /></a></div>
</div>
</article><br />
<div class="EmbeddedTweet-tweet" style="border-color: rgb(225, 232, 237); border-image: initial; border-radius: 0px 0px 4px 4px; border-style: solid; border-width: 0px 1px 1px; padding: 14.4px 20px 11.6px;">
<blockquote cite="https://twitter.com/wbs_tvtokyo/status/809375883676876801" class="Tweet h-entry js-tweetIdInfo subject expanded
is-deciderHtmlWhitespace" data-scribe="section:subject" data-tweet-id="809375883676876801" style="border: none; list-style: none; margin: 0px; padding: 0px;">
<div class="Tweet-header u-cf" style="padding-left: 45px; position: relative; white-space: nowrap;">
<div class="Tweet-brand u-floatRight" style="float: right !important; position: relative; z-index: 1;">
<span class="u-hiddenInNarrowEnv"><a class="FollowButton follow-button profile" data-scribe="component:followbutton" href="https://twitter.com/wbs_tvtokyo" role="button" style="border-radius: 4px; border: 1px solid rgb(85, 172, 238); color: #55acee; display: inline-block; font-size: 14px; font-weight: 700; line-height: 1; outline: 0px; padding: 5.5px 13px 6.5px 11.5px; text-decoration: none;" title="TwitterでWBS(ワールドビジネスサテライト)さんをフォロー"><span class="FollowButton-bird" style="display: inline-block; position: relative; top: 1px;"></span></a></span><br />
<div aria-label="" class="Icon Icon--twitter " role="presentation" style="background-image: url("data:image/svg+xml; background-repeat: no-repeat; background-size: contain; display: inline-block; height: 1.25em; vertical-align: text-bottom; width: 1.25em;" title="">
</div>
<span class="u-hiddenInNarrowEnv"><a class="FollowButton follow-button profile" data-scribe="component:followbutton" href="https://twitter.com/wbs_tvtokyo" role="button" style="border-radius: 4px; border: 1px solid rgb(85, 172, 238); color: #55acee; display: inline-block; font-size: 14px; font-weight: 700; line-height: 1; outline: 0px; padding: 5.5px 13px 6.5px 11.5px; text-decoration: none;" title="TwitterでWBS(ワールドビジネスサテライト)さんをフォロー"><span class="FollowButton-bird" style="display: inline-block; position: relative; top: 1px;">
</span> フォローする</a></span></div>
<div class="TweetAuthor " data-scribe="component:author" style="line-height: 0; margin-top: 2px; max-width: 100%; overflow: hidden !important; text-overflow: ellipsis !important; word-wrap: normal !important;">
<a aria-label="WBS(ワールドビジネスサテライト) (ユーザー名: wbs_tvtokyo)" class="TweetAuthor-link Identity u-linkBlend" data-scribe="element:user_link" href="https://twitter.com/wbs_tvtokyo" style="background-color: transparent; font-weight: inherit; line-height: 1.2; outline: 0px; text-decoration: inherit;"><span class="TweetAuthor-avatar Identity-avatar" style="background-color: transparent; border-radius: 4px; display: inline-block; height: 36px; left: 0px; overflow: hidden; position: absolute; top: 0px; width: 36px;"><img alt="" class="Avatar" data-scribe="element:avatar" data-src-1x="https://pbs.twimg.com/profile_images/450294280074973184/JyhWWpky_normal.png" data-src-2x="https://pbs.twimg.com/profile_images/450294280074973184/JyhWWpky_bigger.png" src="https://pbs.twimg.com/profile_images/450294280074973184/JyhWWpky_bigger.png" style="border: 0px; max-height: 100%; max-width: 100%;" /></span><span class="TweetAuthor-name Identity-name customisable-highlight" data-scribe="element:name" style="font-weight: 700;" title="WBS(ワールドビジネスサテライト)">WBS(ワールドビジネスサテライト)</span> <span class="TweetAuthor-verifiedBadge" data-scribe="element:verified_badge" style="position: absolute; top: 0px;"></span></a><br />
<div aria-label="認証済みアカウント" class="Icon Icon--verified " role="img" style="background-image: url("data:image/svg+xml; background-repeat: no-repeat; background-size: contain; display: inline-block; height: 1.25em; vertical-align: text-bottom; width: 1.11111em;" title="認証済みアカウント">
</div>
<a aria-label="WBS(ワールドビジネスサテライト) (ユーザー名: wbs_tvtokyo)" class="TweetAuthor-link Identity u-linkBlend" data-scribe="element:user_link" href="https://twitter.com/wbs_tvtokyo" style="background-color: transparent; font-weight: inherit; line-height: 1.2; outline: 0px; text-decoration: inherit;"><span class="TweetAuthor-verifiedBadge" data-scribe="element:verified_badge" style="position: absolute; top: 0px;">
<span class="u-hiddenVisually" style="border: 0px !important; clip: rect(1px 1px 1px 1px) !important; height: 1px !important; overflow: hidden !important; padding: 0px !important; position: absolute !important; width: 1px !important;">✔</span></span><span class="TweetAuthor-screenName Identity-screenName" data-scribe="element:screen_name" dir="ltr" style="color: #697882; font-size: 14px;" title="@wbs_tvtokyo">@wbs_tvtokyo</span></a></div>
</div>
<div class="Tweet-body e-entry-content" data-scribe="component:tweet" style="margin-top: 14px;">
<div class="Tweet-text e-entry-title" dir="ltr" lang="ja" style="border: none; cursor: text; direction: ltr; list-style: none; padding: 0px;">
相内優香です。<br />
メガネのJINSが今日「JINS MEME BRIDGE Platform」を発表しました。メガネをかけるだけでまばたきや眼球の動きに連動し、照明をつけたり写真を撮影したりすることができます。”眼球”の可能性はどこまでも広がりそうです。今夜お伝えします。<a class="PrettyLink hashtag customisable" data-query-source="hashtag_click" data-scribe="element:hashtag" dir="ltr" href="https://twitter.com/hashtag/wbs?src=hash" rel="tag" style="background-color: transparent; color: #2b7bb9; outline: 0px; text-decoration: none;"><span class="PrettyLink-prefix">#</span><span class="PrettyLink-value">wbs</span></a></div>
<div class="Tweet-metadata dateline" style="color: #697882; font-size: 14px; margin-top: 3.2px;">
<a class="u-linkBlend u-url customisable-highlight long-permalink" data-datetime="2016-12-15T12:33:42+0000" data-scribe="element:full_timestamp" href="https://twitter.com/wbs_tvtokyo/status/809375883676876801" style="background-color: transparent; font-weight: inherit; outline: 0px; text-decoration: inherit;">2016年12月15日 21:33</a></div>
<ul aria-label="ツイートアクション" class="Tweet-actions" data-scribe="component:actions" role="menu" style="border: none; list-style: none; margin: 8.4px 0px 0px; padding: 0px;">
<li class="Tweet-action" style="display: inline-block;"><a class="TweetAction TweetAction--reply web-intent" data-scribe="element:reply" href="https://twitter.com/intent/tweet?in_reply_to=809375883676876801" style="background-color: transparent; color: #697882; outline: 0px; text-decoration: none;"><div aria-label="返信" class="Icon Icon--reply TweetAction-icon" role="img" style="background-image: url("data:image/svg+xml; background-repeat: no-repeat; background-size: contain; display: inline-block; height: 1.25em; transform: scaleX(1); vertical-align: text-bottom; width: 1.07639em;" title="返信">
</div>
</a></li>
<li class="Tweet-action" style="display: inline-block; margin-left: 14px;"><a class="TweetAction TweetAction--retweet web-intent" data-scribe="element:retweet" href="https://twitter.com/intent/retweet?tweet_id=809375883676876801" style="background-color: transparent; color: #697882; outline: 0px; text-decoration: none;"><div aria-label="リツイート" class="Icon Icon--retweet TweetAction-icon" role="img" style="background-image: url("data:image/svg+xml; background-repeat: no-repeat; background-size: contain; display: inline-block; height: 1.25em; transform: scaleX(1); vertical-align: text-bottom; width: 1.28472em;" title="リツイート">
</div>
<span aria-hidden="true" class="TweetAction-stat" data-scribe="element:retweet_count" style="display: inline-block; font-size: 14px; vertical-align: text-bottom;">146</span><span class="u-hiddenVisually" style="border: 0px !important; clip: rect(1px 1px 1px 1px) !important; height: 1px !important; overflow: hidden !important; padding: 0px !important; position: absolute !important; width: 1px !important;">146件のリツイート</span></a></li>
<li class="Tweet-action" style="display: inline-block; margin-left: 14px;"><a class="TweetAction TweetAction--heart web-intent" data-scribe="element:heart" href="https://twitter.com/intent/like?tweet_id=809375883676876801" style="background-color: transparent; color: #697882; outline: 0px; text-decoration: none;"><div aria-label="いいね" class="Icon Icon--heart TweetAction-icon" role="img" style="background-image: url("data:image/svg+xml; background-repeat: no-repeat; background-size: contain; display: inline-block; height: 1.25em; vertical-align: text-bottom; width: 0.9375em;" title="いいね">
</div>
<span aria-hidden="true" class="TweetAction-stat" data-scribe="element:heart_count" style="display: inline-block; font-size: 14px; vertical-align: text-bottom;">331</span><span class="u-hiddenVisually" style="border: 0px !important; clip: rect(1px 1px 1px 1px) !important; height: 1px !important; overflow: hidden !important; padding: 0px !important; position: absolute !important; width: 1px !important;">いいね331件</span></a></li>
</ul>
</div>
</blockquote>
</div>
</div>
<div class="resize-sensor" style="bottom: 0px; left: 0px; overflow: hidden; position: absolute; right: 0px; top: 0px; visibility: hidden; z-index: -1;">
<div class="resize-sensor-expand" style="bottom: 0px; left: 0px; overflow: hidden; position: absolute; right: 0px; top: 0px; visibility: hidden; z-index: -1;">
<div style="height: 526px; left: 0px; position: absolute; top: 0px; transition: 0s; width: 510px;">
</div>
</div>
<div class="resize-sensor-shrink" style="bottom: 0px; left: 0px; overflow: hidden; position: absolute; right: 0px; top: 0px; visibility: hidden; z-index: -1;">
<div style="height: 1031.12px; left: 0px; position: absolute; top: 0px; transition: 0s; width: 1000px;">
</div>
</div>
</div>
</div>
<h2 style="border-bottom: 1px solid rgb(238, 238, 238); box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: normal; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="経緯" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/7ee6288dec2be10f86b1#%E7%B5%8C%E7%B7%AF" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>経緯</h2>
<div style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
JINSさんから私のブログを見たと連絡があり、展示の依頼があり受けさせていただきました。<br />
間接的にアプリや開発物が何らかの媒体に紹介されることはありますが、成果物が実際に実店舗で紹介される、またTVで放映されるのは今まで経験したことがなかったので貴重な経験で有り難いなぁと思っています。またそれがメガネのJINSさんに取り上げられるとは!!</div>
<h2 style="border-bottom: 1px solid rgb(238, 238, 238); box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: normal; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="jins-memeを使った過去の開発ブログ" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/7ee6288dec2be10f86b1#jins-meme%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%9F%E9%81%8E%E5%8E%BB%E3%81%AE%E9%96%8B%E7%99%BA%E3%83%96%E3%83%AD%E3%82%B0" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>JINS MEMEを使った過去の開発ブログ</h2>
<div style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
一年以上前ですがいろいろやってました。</div>
<ul style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.7; list-style: none; margin: 1em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit; list-style-type: disc;"><a href="https://yuichi-dev.blogspot.jp/2015/12/Attitude-monitoring-jins-meme.html" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">姿勢監視チェッカー作ってみた</a></li>
<li style="box-sizing: inherit; list-style-type: disc;"><a href="https://yuichi-dev.blogspot.jp/2015/12/blink-sidelong-glance-shoot-by-glasses-jins-meme.html" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">メガネ美女子が流し目でシャッター by JINS MEME</a></li>
<li style="box-sizing: inherit; list-style-type: disc;"><a href="https://yuichi-dev.blogspot.jp/2015/12/jins-meme-theta-s-or.html" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">【JINS MEME × THETA S】流し目 or まばたきシャッターの実装</a></li>
</ul>
<h2 style="border-bottom: 1px solid rgb(238, 238, 238); box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: normal; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="最後に" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/7ee6288dec2be10f86b1#%E6%9C%80%E5%BE%8C%E3%81%AB" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>最後に</h2>
<twitterwidget class="twitter-tweet twitter-tweet-rendered" data-tweet-id="809375883676876801" id="twitter-widget-0" style="box-sizing: inherit; display: block; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; margin-bottom: 10px; margin-top: 10px; max-width: 100%; min-width: 220px; position: static; transform: rotate(0deg); visibility: visible; width: 500px;"></twitterwidget><br />
<div style="box-sizing: inherit; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
JINSさんにはご紹介、ご協力いただき、ありがとうございました。<br />
JINS MEMEは様々なデバイスと連携したり拡張できるデバイスなので他にも面白い使い方ができるんじゃないでしょうか。<br />
今後デベロッパーコミュニティなどが盛り上がるようにハッカソンや勉強会を開催されるようですので是非ご興味ある方は参加してみてください。<br />
<a class="autolink" href="https://eventdots.jp/community/jinsmeme/event" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">https://eventdots.jp/community/jinsmeme/event</a></div>
</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-30995129838553016182016-11-25T08:10:00.000+09:002016-12-14T10:32:30.149+09:00Xcode8でビルドが遅すぎるのを解消した件(Swift パフォーマンス改善)<div style="background-color: white; box-sizing: border-box; line-height: 1.875; margin-bottom: 1.4em;">
<div style="box-sizing: inherit; line-height: 1.875; margin-bottom: 1.4em;">
<span style="color: #4a4a4a; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica neue" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;"><span style="font-size: 16.1px;">Qiitaにも同様の投稿をしています。</span></span><br />
<span style="color: #4a4a4a; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica neue" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;"><span style="font-size: 16.1px;"><a href="http://qiita.com/you_matz/items/e95f30023eccc8d96357">http://qiita.com/you_matz/items/e95f30023eccc8d96357</a></span></span><br />
<br />
<span style="color: #4a4a4a; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica neue" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;"><span style="font-size: 16.1px;">2016年11月現在、最新(Xcode8.1環境下での)のコンパイル時間の計測方法が見当たらないので分析方法まで調査した。</span></span><br />
<span style="color: #4a4a4a; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica neue" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;"><span style="font-size: 16.1px;">2分程度かかっていたビルドが10秒ほどに短縮できました。</span></span><br />
<span style="color: #4a4a4a; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica neue" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;"><span style="font-size: 16.1px;">※ビルドするマシンのスペック、設定、ファイル数、コードの書き方にもよるので、</span></span><br />
<span style="color: #4a4a4a; font-family: , "blinkmacsystemfont" , "segoe ui" , "helvetica neue" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;"><span style="font-size: 16.1px;">n%,n秒速くなったというのは相対的な値なので予めご了承ください。</span></span></div>
<h2 style="border-bottom: 1px solid rgb(238, 238, 238); box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="はじめに" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E3%81%AF%E3%81%98%E3%82%81%E3%81%AB" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>はじめに</h2>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
100クラス弱のswiftのプロジェクトで2分強ビルドに時間がかかっていたので、おかしいなと思い、おそらく静的にベタ書きした多次元配列に型情報を与えていないからだろうなと分かっていたが、いい機会なので原因を調査してみた。</div>
<h2 style="border-bottom: 1px solid rgb(238, 238, 238); box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="プロジェクトのビルド時間の計測" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AE%E3%83%93%E3%83%AB%E3%83%89%E6%99%82%E9%96%93%E3%81%AE%E8%A8%88%E6%B8%AC" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>プロジェクトのビルド時間の計測</h2>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
こちらを参考に(<a href="http://qiita.com/rizumita/items/913b05d799b3712260f6" id="reference-96fc4eec376da731f4f4" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;">Swiftのメソッド毎のコンパイル時間を計測してビルド時間を短縮する</a>)<br />
<br style="box-sizing: inherit;" />
単にビルドが遅いと言われても、実質どのくらい時間がかかっているかわからないので計測<br />
コンソールで以下実行<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES</code></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
その後、Xcode リスタート、クリーン、ビルドすると<br />
以下のように時間が0.036sと表示される<br />
これは18ファイルだけのBuildTimeAnalyzerのMacアプリなので速い<br />
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/f25d6583-aeda-f5da-ec7c-827ba363d869.png" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank"><img alt="スクリーンショット 2016-11-19 午後5.37.15.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/f25d6583-aeda-f5da-ec7c-827ba363d869.png" style="border-style: none; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="スクリーンショット 2016-11-19 午後5.37.15.png" /></a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
これくらいビルド時間が速いと気にしなくていいですが、ビルド時間が遅い場合は以下で計測</div>
<h2 style="border-bottom: 1px solid rgb(238, 238, 238); box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="ファイル毎のコンパイル時間の計測" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E6%AF%8E%E3%81%AE%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%AB%E6%99%82%E9%96%93%E3%81%AE%E8%A8%88%E6%B8%AC" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>ファイル毎のコンパイル時間の計測</h2>
<h3 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 1.1em 0px 0.7em;">
<span class="fragment" id="まずxctoolで試すxcode8でxctoolのbuildコマンドは使えなくなっている" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E3%81%BE%E3%81%9Axctool%E3%81%A7%E8%A9%A6%E3%81%99xcode8%E3%81%A7xctool%E3%81%AEbuild%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%AF%E4%BD%BF%E3%81%88%E3%81%AA%E3%81%8F%E3%81%AA%E3%81%A3%E3%81%A6%E3%81%84%E3%82%8B" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>まずxctoolで試す(※Xcode8でxctoolのbuildコマンドは使えなくなっている)</h3>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
xctoolでファイル毎のコンパイル時間、メソッド毎のコンパイル時間を計測しようとしたが使えない、、、(xctoolでのbuildはXcode7だけ)<br />
<a class="autolink" href="https://github.com/facebook/xctool#building-xcode-7-only" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">https://github.com/facebook/xctool#building-xcode-7-only</a></div>
<h3 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="普通にxcodebuildで" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E6%99%AE%E9%80%9A%E3%81%ABxcodebuild%E3%81%A7" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>普通にxcodebuildで</h3>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
プロジェクトルートにて以下コマンド<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">xcodebuild -workspace YOUR-APP.xcworkspace/ -scheme YOUR-APP clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep .[0-9]ms | grep -v ^0.[0-9]ms | sort -nr > buildResult.txt</code></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
clean build、 <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">OTHER_SWIFT_FLAGS</code> に <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">-Xfrontend -debug-time-function-bodies</code> を追加することでメソッド、プロパティ毎に計測可能となる</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">YOUR-APP</code>は適宜変更してください。cocoapods使用の場合は<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">-workspace</code> ですが、<br />
していない場合<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">-project YOUR−APP.xcodeproj/</code><br />
必要な行だけ抽出して、コンパイルに時間を用するファイル、メソッド、プロパティ順でソート</div>
<h3 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="結果その1全ファイル" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E7%B5%90%E6%9E%9C%E3%81%9D%E3%81%AE1%E5%85%A8%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>結果その1(全ファイル)</h3>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">7644.0ms /Users/Hoge/develop/iOS/App/Pods/PagingMenuController/Pod/Classes/MenuItemView.swift:189:18 private func layoutMultiLineLabel()
7643.1ms /Users/Hoge/develop/iOS/App/Pods/PagingMenuController/Pod/Classes/MenuItemView.swift:189:18 private func layoutMultiLineLabel()
1158.6ms /Users/Hoge/develop/iOS/App/Pods/Siren/Siren/Siren.swift:590:10 final func setAlertType() -> SirenAlertType
1122.0ms /Users/Hoge/develop/iOS/App/Pods/Siren/Siren/Siren.swift:590:10 final func setAlertType() -> SirenAlertType
677.9ms /Users/Hoge/develop/iOS/App/Pods/ObjectMapper/ObjectMapper/Core/Operators.swift:485:13 public func <- :="" mappable="" ransform="" transform.object="" transformtype="" where="">(inout left: Dictionary<string ransform.object="">?, right: (Map, Transform))
671.2ms /Users/Hoge/develop/iOS/App/Pods/ObjectMapper/ObjectMapper/Core/Operators.swift:485:13 public func <- :="" mappable="" ransform="" transform.object="" transformtype="" where="">(inout left: Dictionary<string ransform.object="">?, right: (Map, Transform))
608.4ms /Users/Hoge/develop/iOS/App/Pods/ObjectMapper/ObjectMapper/Core/Operators.swift:502:13 public func <- :="" mappable="" ransform="" transform.object="" transformtype="" where="">(inout left: Dictionary<string ransform.object="">!, right: (Map, Transform))
</string></-></string></-></string></-></pre>
</div>
</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
pods内コンパイル時間も入っているけど、1ファイルだけで7.6秒はやばい、、</div>
<h3 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="build-time-analyzer-for-xcodeで計測こちらがおすすめ" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#build-time-analyzer-for-xcode%E3%81%A7%E8%A8%88%E6%B8%AC%E3%81%93%E3%81%A1%E3%82%89%E3%81%8C%E3%81%8A%E3%81%99%E3%81%99%E3%82%81" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>Build Time Analyzer for Xcodeで計測(こちらがおすすめ)</h3>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
Xcode8になってからAlcatraz(PackageManager)が使えないので、そのままソースからビルドしてMacアプリを起動<br />
ソースはこちらから<br />
<a class="autolink" href="https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode/releases" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode/releases</a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
アプリを起動すると以下のウィンドウが立ち上がる</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/f6de2d9f-e25a-1e85-afe0-99460a9ad98b.png" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank"><img alt="スクリーンショット 2016-11-20 午後1.51.01-1.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/f6de2d9f-e25a-1e85-afe0-99460a9ad98b.png" style="border-style: none; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="スクリーンショット 2016-11-20 午後1.51.01-1.png" /></a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
instructionsに沿って、<br />
Build Settings > Swift Compiler - Custom Flags</div>
<ol style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.7; list-style: none; margin: 1em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit; list-style-type: decimal;"><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">OTHER_SWIFT_FLAGS</code> に <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">-Xfrontend -debug-time-function-bodies</code> を追加</li>
<li style="box-sizing: inherit; list-style-type: decimal;">クリーン</li>
<li style="box-sizing: inherit; list-style-type: decimal;">ビルド</li>
<li style="box-sizing: inherit; list-style-type: decimal;">以下のようなファイル、メソッド毎のコンパイル時間が表示された画面が起動</li>
</ol>
<h3 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="結果その2gui" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E7%B5%90%E6%9E%9C%E3%81%9D%E3%81%AE2gui" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>結果その2(GUI)</h3>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/665328fc-c6a0-088b-5f02-dc0761e38be0.png" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank"><img alt="スクリーンショット 2016-11-20 午後2.31.13.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/665328fc-c6a0-088b-5f02-dc0761e38be0.png" style="border-style: none; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="スクリーンショット 2016-11-20 午後2.31.13.png" /></a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
サンプルプロジェクトでの結果なので3秒とすぐです。結果1とは違いPods内は含まれません。<br />
行選択でファイルまで飛ぶことができ、<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">per file</code> にチェックでファイルごとの時間もわかる<br />
これで、どのファイルのどの箇所がコンパイルするのに時間がかかるのか予測がつきます。</div>
<h3 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="カスタムフラグを追加" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%E3%83%95%E3%83%A9%E3%82%B0%E3%82%92%E8%BF%BD%E5%8A%A0" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>カスタムフラグを追加</h3>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
2016/12/11追記 swift3.0以降で有効。カスタムフラグを追加<br />
Build Time Analyzerを起動する必要がないので現時点ではこちらの方が便利かもしれません。</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
Build Settings > Swift Compiler - Custom Flags<br />
OTHER_SWIFT_FLAGS に <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">-Xfrontend</code> と <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">-warn-long-function-bodies=100</code> を追加<br />
これによってコンパイルに100ms以上かかっている箇所をwarningで出してくれます。<br />
以下のような表示です。</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/68a146bd-11b5-b8bb-5888-d12547dc0f74.png" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank"><img alt="スクリーンショット 2016-12-12 午前10.11.30.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/68a146bd-11b5-b8bb-5888-d12547dc0f74.png" style="border-style: none; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" width="260" /></a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
5249msタイプチェックにかかっているとのこと、クリックして修正箇所に飛べます。<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">-warn-long-function-bodies=100</code>の100はワーニングを出すかの敷居値なので、<br />
1秒であれば1000, 0.5秒であれば500にしてもいい。<br />
これらのオプションは将来的には予告なしにサポートされなくなる可能性もあります。</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
参考:<a href="http://khanlou.com/2016/12/guarding-against-long-compiles/" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">Guarding Against Long Compiles</a></div>
<h2 style="border-bottom: 1px solid rgb(238, 238, 238); box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="改善策" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E6%94%B9%E5%96%84%E7%AD%96" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>改善策</h2>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
簡単にできるものから<br />
※マシンの性能上げろとか買い換えろとか単純な策は誰でも思いつくのでなしです</div>
<h3 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="設定レベル-事前にできること" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E8%A8%AD%E5%AE%9A%E3%83%AC%E3%83%99%E3%83%AB-%E4%BA%8B%E5%89%8D%E3%81%AB%E3%81%A7%E3%81%8D%E3%82%8B%E3%81%93%E3%81%A8" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>設定レベル-事前にできること</h3>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="optimization-levelを見直す" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#optimization-level%E3%82%92%E8%A6%8B%E7%9B%B4%E3%81%99" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>Optimization Levelを見直す</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
Build Settingの中にApple LLVM8.0 - Code GenerationとSwift Compiler があります。<br />
Optimization Levelがデフォルトで<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">Debug None[-Onone]</code>となっていますが、<br />
まれに<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">Fast</code>に設定している場合があるのでこれをDebug時は<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">None</code>とすることで最適化が行われず、ビルド時間が短くなります。リリースビルド用では<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">fast</code>,<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">Fast, Whole Module Optimization</code>指定して最適化が行われるようにするべきです。</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/6382cb51-ceaa-77e9-8ef0-e78306f0e996.png" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank"><img alt="スクリーンショット 2016-11-19 午後11.47.06.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/6382cb51-ceaa-77e9-8ef0-e78306f0e996.png" style="border-style: none; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="スクリーンショット 2016-11-19 午後11.47.06.png" /></a></div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="user-definedにswift_whole_module_optimizationを追加" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#user-defined%E3%81%ABswift_whole_module_optimization%E3%82%92%E8%BF%BD%E5%8A%A0" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>User-DefinedにSWIFT_WHOLE_MODULE_OPTIMIZATIONを追加</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
Build Setting > Add User-Defined Settingに以下を追加<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">SWIFT_WHOLE_MODULE_OPTIMIZATION = YES</code><br />
最適化がかかる場合、ビルド時間が半分程に短縮できました。<br />
リリース用ビルドでは最適化がかかるのでテストサーバとか配布用サーバなどでこの設定は有効です。</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
<a class="autolink" href="http://stackoverflow.com/questions/39547197/xcode-8-0-swift-3-0-slow-indexing-and-building" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">http://stackoverflow.com/questions/39547197/xcode-8-0-swift-3-0-slow-indexing-and-building</a></div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="コンパイルの並列化" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%AB%E3%81%AE%E4%B8%A6%E5%88%97%E5%8C%96" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>コンパイルの並列化</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
Macのコア数を確認<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">system_profiler SPHardwareDataType</code><br />
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/c047ce0a-7287-a859-1011-2701e29d3a50.png" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank"><img alt="スクリーンショット 2016-11-19 午後8.01.49.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/c047ce0a-7287-a859-1011-2701e29d3a50.png" style="border-style: none; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="スクリーンショット 2016-11-19 午後8.01.49.png" /></a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
コア数に応じて、同時実行数を指定<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">defaults write com.apple.dt.Xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks 2</code></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
これでビルド時間が半分以下に縮む</div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="pods内コンパイルをスキップ" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#pods%E5%86%85%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%AB%E3%82%92%E3%82%B9%E3%82%AD%E3%83%83%E3%83%97" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>Pods内コンパイルをスキップ</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
これはあまりおすすめできませんが紹介しておきます。</div>
<ul style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.7; list-style: none; margin: 1em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit; list-style-type: disc;">Product->Scheme->Edit Schemeでスキーマの編集画面へ</li>
<li style="box-sizing: inherit; list-style-type: disc;">左のリストからBuildを選択し、右画面のFind Implicit Dependenciesのチェックを外す</li>
</ul>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
※Pods内を変更してもビルドが走らないので注意<br />
※Find Implicit Dependanciesにチェックをつけてクリーン、ビルド</div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="cocoapodsをcarthageに切り替える" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#cocoapods%E3%82%92carthage%E3%81%AB%E5%88%87%E3%82%8A%E6%9B%BF%E3%81%88%E3%82%8B" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>CocoaPodsをCarthageに切り替える</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
Carthage対応のライブラリはPodsでインストールしない方がよいです</div>
<ul style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.7; list-style: none; margin: 1em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit; list-style-type: disc;">事前にフレームワークを作成できるのでコンパイルなしでその分コンパイル時間を短縮できる</li>
<li style="box-sizing: inherit; list-style-type: disc;">つまりPodsだとクリーンインストール毎にビルドし直す必要があるが、Carthageはビルドし直す必要がない</li>
</ul>
<h3 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="コードレベル" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E3%82%B3%E3%83%BC%E3%83%89%E3%83%AC%E3%83%99%E3%83%AB" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>コードレベル</h3>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="型推論させない" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E5%9E%8B%E6%8E%A8%E8%AB%96%E3%81%95%E3%81%9B%E3%81%AA%E3%81%84" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>型推論させない</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
明示的に型を付与させる<br />
例えば以下のようなDictionaryを型情報なしで書くと型推論が働いて、コンパイルに時間がかかるので、</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">BadDictionary.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: inherit; font-weight: 700;">static</span> <span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="n" style="box-sizing: inherit;">hogeDict</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span>
<span class="p" style="box-sizing: inherit;">[</span>
<span class="p" style="box-sizing: inherit;">[</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1"</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">:</span> <span class="p" style="box-sizing: inherit;">[</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-1"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-2"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-3"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-4"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-5"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-6"</span>
<span class="p" style="box-sizing: inherit;">]</span>
<span class="p" style="box-sizing: inherit;">],</span>
<span class="p" style="box-sizing: inherit;">[</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge2"</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">:</span> <span class="p" style="box-sizing: inherit;">[</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge2-1"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge2-2"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="p" style="box-sizing: inherit;">]</span>
<span class="p" style="box-sizing: inherit;">]</span>
<span class="p" style="box-sizing: inherit;">]</span>
</pre>
</div>
</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
型を付与</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">GoodDictionary.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: inherit; font-weight: 700;">static</span> <span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="nl" style="box-sizing: inherit;">hogeDict</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">[</span><span class="n" style="box-sizing: inherit;">Dictionary</span><span class="o" style="box-sizing: inherit; font-weight: 700;"><</span><span class="n" style="box-sizing: inherit;">String</span><span class="p" style="box-sizing: inherit;">,</span> <span class="n" style="box-sizing: inherit;">Array</span><span class="o" style="box-sizing: inherit; font-weight: 700;"><</span><span class="n" style="box-sizing: inherit;">String</span><span class="o" style="box-sizing: inherit; font-weight: 700;">>></span><span class="p" style="box-sizing: inherit;">]</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span>
<span class="p" style="box-sizing: inherit;">[</span>
<span class="p" style="box-sizing: inherit;">[</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1"</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">:</span> <span class="p" style="box-sizing: inherit;">[</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-1"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-2"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-3"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-4"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-5"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge1-6"</span>
<span class="p" style="box-sizing: inherit;">]</span>
<span class="p" style="box-sizing: inherit;">],</span>
<span class="p" style="box-sizing: inherit;">[</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge2"</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">:</span> <span class="p" style="box-sizing: inherit;">[</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge2-1"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="s" style="box-sizing: inherit; color: #dd1144;">"hoge2-2"</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="p" style="box-sizing: inherit;">]</span>
<span class="p" style="box-sizing: inherit;">]</span>
<span class="p" style="box-sizing: inherit;">]</span>
</pre>
</div>
</div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="配列の結合は以下のように" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E9%85%8D%E5%88%97%E3%81%AE%E7%B5%90%E5%90%88%E3%81%AF%E4%BB%A5%E4%B8%8B%E3%81%AE%E3%82%88%E3%81%86%E3%81%AB" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>配列の結合は以下のように</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
配列内容にもよりますが、コンパイルに時間がかかる可能性があります。<br />
文字列連結で複雑な連結の仕方をしている場合も同様。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">BadArrayConcat.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Compiles multiple seconds</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="n" style="box-sizing: inherit;">slowArray</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="n" style="box-sizing: inherit;">array1</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">array2</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">array3</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">array4</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">array5</span>
<span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Compiles very fast</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="n" style="box-sizing: inherit;">array</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="n" style="box-sizing: inherit;">Array</span><span class="p" style="box-sizing: inherit;">([</span><span class="n" style="box-sizing: inherit;">array1</span><span class="p" style="box-sizing: inherit;">,</span> <span class="n" style="box-sizing: inherit;">array2</span><span class="p" style="box-sizing: inherit;">,</span> <span class="n" style="box-sizing: inherit;">array3</span><span class="p" style="box-sizing: inherit;">,</span> <span class="n" style="box-sizing: inherit;">array4</span><span class="p" style="box-sizing: inherit;">,</span> <span class="n" style="box-sizing: inherit;">array5</span><span class="p" style="box-sizing: inherit;">].</span><span class="n" style="box-sizing: inherit;">flatten</span><span class="p" style="box-sizing: inherit;">())</span>
</pre>
</div>
</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
または+で連結するよりappendで追加</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">BetterArrayConcat.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="k" style="box-sizing: inherit; font-weight: 700;">return</span> <span class="n" style="box-sizing: inherit;">ArrayOfStuff</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="p" style="box-sizing: inherit;">[</span><span class="n" style="box-sizing: inherit;">Stuff</span><span class="p" style="box-sizing: inherit;">]</span>
<span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// rather than</span>
<span class="n" style="box-sizing: inherit;">ArrayOfStuff</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">append</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">stuff</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">return</span> <span class="n" style="box-sizing: inherit;">ArrayOfStuff</span>
</pre>
</div>
</div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="演算子は使用しない" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E6%BC%94%E7%AE%97%E5%AD%90%E3%81%AF%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%AA%E3%81%84" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>??演算子は使用しない</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
これはだめ</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">NilCoalescingOperator.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="n" style="box-sizing: inherit;">name</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="s" style="box-sizing: inherit; color: #dd1144;">"\(someString ?? "")"</span>
</pre>
</div>
</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
はじめの複雑な連結はやめて、適切にアンラップ<br />
メソッド内、ビルド時間を99.4%削減</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">VariableConcat.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Build time: 5238.3ms</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">return</span> <span class="bp" style="box-sizing: inherit; color: #999999;">CGSize</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">width</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">size</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">width</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">rightView</span><span class="o" style="box-sizing: inherit; font-weight: 700;">?</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">bounds</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">width</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">??</span> <span class="mi" style="box-sizing: inherit; color: #009999;">0</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">leftView</span><span class="o" style="box-sizing: inherit; font-weight: 700;">?</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">bounds</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">width</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">??</span> <span class="mi" style="box-sizing: inherit; color: #009999;">0</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="mi" style="box-sizing: inherit; color: #009999;">22</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">height</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">bounds</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">height</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Build time: 32.4ms</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">var</span> <span class="nl" style="box-sizing: inherit;">padding</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">CGFloat</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="mi" style="box-sizing: inherit; color: #009999;">22</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">if</span> <span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="n" style="box-sizing: inherit;">rightView</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="n" style="box-sizing: inherit;">rightView</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">padding</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+=</span> <span class="n" style="box-sizing: inherit;">rightView</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">bounds</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">width</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">if</span> <span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="n" style="box-sizing: inherit;">leftView</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="n" style="box-sizing: inherit;">leftView</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">padding</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+=</span> <span class="n" style="box-sizing: inherit;">leftView</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">bounds</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">width</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">return</span> <span class="n" style="box-sizing: inherit;">CGSizeMake</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">size</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">width</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">padding</span><span class="p" style="box-sizing: inherit;">,</span> <span class="n" style="box-sizing: inherit;">bounds</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">height</span><span class="p" style="box-sizing: inherit;">)</span>
</pre>
</div>
</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
アンラップの箇所は<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">guard let</code>でもよい<br />
コード的にも読みやすいというのはコンパイラも解釈しやすいということでしょうか</div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="三項演算子もだめ" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E4%B8%89%E9%A0%85%E6%BC%94%E7%AE%97%E5%AD%90%E3%82%82%E3%81%A0%E3%82%81" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>三項演算子もだめ</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
92.9%削減</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">TernaryOperator.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Build time: 239.0ms</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="n" style="box-sizing: inherit;">labelNames</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="n" style="box-sizing: inherit;">type</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">==</span> <span class="mi" style="box-sizing: inherit; color: #009999;">0</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">?</span> <span class="p" style="box-sizing: inherit;">(</span><span class="mf" style="box-sizing: inherit; color: #009999;">1.</span><span class="p" style="box-sizing: inherit;">.</span><span class="mf" style="box-sizing: inherit; color: #009999;">.5</span><span class="p" style="box-sizing: inherit;">).</span><span class="n" style="box-sizing: inherit;">map</span><span class="p" style="box-sizing: inherit;">{</span><span class="n" style="box-sizing: inherit;">type0ToString</span><span class="p" style="box-sizing: inherit;">(</span><span class="err" style="background-color: #e3d2d2; box-sizing: inherit; color: #a61717;">$</span><span class="mi" style="box-sizing: inherit; color: #009999;">0</span><span class="p" style="box-sizing: inherit;">)}</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">:</span> <span class="p" style="box-sizing: inherit;">(</span><span class="mf" style="box-sizing: inherit; color: #009999;">0.</span><span class="p" style="box-sizing: inherit;">.</span><span class="mf" style="box-sizing: inherit; color: #009999;">.2</span><span class="p" style="box-sizing: inherit;">).</span><span class="n" style="box-sizing: inherit;">map</span><span class="p" style="box-sizing: inherit;">{</span><span class="n" style="box-sizing: inherit;">type1ToString</span><span class="p" style="box-sizing: inherit;">(</span><span class="err" style="background-color: #e3d2d2; box-sizing: inherit; color: #a61717;">$</span><span class="mi" style="box-sizing: inherit; color: #009999;">0</span><span class="p" style="box-sizing: inherit;">)}</span>
<span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Build time: 16.9ms</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">var</span> <span class="nl" style="box-sizing: inherit;">labelNames</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">[</span><span class="n" style="box-sizing: inherit;">String</span><span class="p" style="box-sizing: inherit;">]</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">if</span> <span class="n" style="box-sizing: inherit;">type</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">==</span> <span class="mi" style="box-sizing: inherit; color: #009999;">0</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">labelNames</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="p" style="box-sizing: inherit;">(</span><span class="mf" style="box-sizing: inherit; color: #009999;">1.</span><span class="p" style="box-sizing: inherit;">.</span><span class="mf" style="box-sizing: inherit; color: #009999;">.5</span><span class="p" style="box-sizing: inherit;">).</span><span class="n" style="box-sizing: inherit;">map</span><span class="p" style="box-sizing: inherit;">{</span><span class="n" style="box-sizing: inherit;">type0ToString</span><span class="p" style="box-sizing: inherit;">(</span><span class="err" style="background-color: #e3d2d2; box-sizing: inherit; color: #a61717;">$</span><span class="mi" style="box-sizing: inherit; color: #009999;">0</span><span class="p" style="box-sizing: inherit;">)}</span>
<span class="p" style="box-sizing: inherit;">}</span> <span class="k" style="box-sizing: inherit; font-weight: 700;">else</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">labelNames</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="p" style="box-sizing: inherit;">(</span><span class="mf" style="box-sizing: inherit; color: #009999;">0.</span><span class="p" style="box-sizing: inherit;">.</span><span class="mf" style="box-sizing: inherit; color: #009999;">.2</span><span class="p" style="box-sizing: inherit;">).</span><span class="n" style="box-sizing: inherit;">map</span><span class="p" style="box-sizing: inherit;">{</span><span class="n" style="box-sizing: inherit;">type1ToString</span><span class="p" style="box-sizing: inherit;">(</span><span class="err" style="background-color: #e3d2d2; box-sizing: inherit; color: #a61717;">$</span><span class="mi" style="box-sizing: inherit; color: #009999;">0</span><span class="p" style="box-sizing: inherit;">)}</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="closureの引数の型を明示する" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#closure%E3%81%AE%E5%BC%95%E6%95%B0%E3%81%AE%E5%9E%8B%E3%82%92%E6%98%8E%E7%A4%BA%E3%81%99%E3%82%8B" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>Closureの引数の型を明示する</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
上記の例の用に$0でアクセスできますが、型推論が働いてしまうので明示的に型を付与</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">Closure.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="n" style="box-sizing: inherit;">cities</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="p" style="box-sizing: inherit;">[</span><span class="s" style="box-sizing: inherit; color: #dd1144;">"kyoto"</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s" style="box-sizing: inherit; color: #dd1144;">"tokyo"</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s" style="box-sizing: inherit; color: #dd1144;">"new york"</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s" style="box-sizing: inherit; color: #dd1144;">"bogota"</span><span class="p" style="box-sizing: inherit;">,</span> <span class="s" style="box-sizing: inherit; color: #dd1144;">"mumbai"</span><span class="p" style="box-sizing: inherit;">]</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">let</span> <span class="n" style="box-sizing: inherit;">numbers</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="p" style="box-sizing: inherit;">[</span><span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: #009999;">3</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: #009999;">6</span><span class="p" style="box-sizing: inherit;">,</span> <span class="mi" style="box-sizing: inherit; color: #009999;">9</span><span class="p" style="box-sizing: inherit;">]</span>
<span class="n" style="box-sizing: inherit;">zip</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">cities</span><span class="p" style="box-sizing: inherit;">,</span> <span class="n" style="box-sizing: inherit;">numbers</span><span class="p" style="box-sizing: inherit;">).</span><span class="n" style="box-sizing: inherit;">forEach</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="n" style="box-sizing: inherit;">print</span><span class="p" style="box-sizing: inherit;">(</span><span class="err" style="background-color: #e3d2d2; box-sizing: inherit; color: #a61717;">$</span><span class="mf" style="box-sizing: inherit; color: #009999;">0.0</span><span class="p" style="box-sizing: inherit;">,</span> <span class="err" style="background-color: #e3d2d2; box-sizing: inherit; color: #a61717;">$</span><span class="mf" style="box-sizing: inherit; color: #009999;">0.1</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
<span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// rather than </span>
<span class="n" style="box-sizing: inherit;">zip</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">cities</span><span class="p" style="box-sizing: inherit;">,</span> <span class="n" style="box-sizing: inherit;">numbers</span><span class="p" style="box-sizing: inherit;">).</span><span class="n" style="box-sizing: inherit;">forEach</span> <span class="p" style="box-sizing: inherit;">{</span> <span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">str</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">String</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">num</span><span class="p" style="box-sizing: inherit;">:</span> <span class="n" style="box-sizing: inherit;">Int</span><span class="p" style="box-sizing: inherit;">)</span> <span class="k" style="box-sizing: inherit; font-weight: 700;">in</span>
<span class="n" style="box-sizing: inherit;">print</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">str</span><span class="p" style="box-sizing: inherit;">,</span> <span class="n" style="box-sizing: inherit;">num</span><span class="p" style="box-sizing: inherit;">)</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="多重キャスト" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E5%A4%9A%E9%87%8D%E3%82%AD%E3%83%A3%E3%82%B9%E3%83%88" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>多重キャスト</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
普通はこんなことしないと思いますが、<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">CGFloat</code>を<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">CGFloat</code>にキャストしたり、<br />
驚くべきごとに、うっかりミスのこの箇所だけで3.4秒かかってしまっていた。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">MultiCast.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Build time: 3431.7ms</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">return</span> <span class="n" style="box-sizing: inherit;">CGFloat</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">M_PI</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">*</span> <span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">CGFloat</span><span class="p" style="box-sizing: inherit;">((</span><span class="n" style="box-sizing: inherit;">hour</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">hourDelta</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">CGFloat</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">minute</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">minuteDelta</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">/</span> <span class="mi" style="box-sizing: inherit; color: #009999;">60</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">*</span> <span class="mi" style="box-sizing: inherit; color: #009999;">5</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">-</span> <span class="mi" style="box-sizing: inherit; color: #009999;">15</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">*</span> <span class="n" style="box-sizing: inherit;">unit</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">/</span> <span class="mi" style="box-sizing: inherit; color: #009999;">180</span>
<span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Build time: 3.0ms</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">return</span> <span class="n" style="box-sizing: inherit;">CGFloat</span><span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">M_PI</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">*</span> <span class="p" style="box-sizing: inherit;">((</span><span class="n" style="box-sizing: inherit;">hour</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">hourDelta</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="p" style="box-sizing: inherit;">(</span><span class="n" style="box-sizing: inherit;">minute</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">+</span> <span class="n" style="box-sizing: inherit;">minuteDelta</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">/</span> <span class="mi" style="box-sizing: inherit; color: #009999;">60</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">*</span> <span class="mi" style="box-sizing: inherit; color: #009999;">5</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">-</span> <span class="mi" style="box-sizing: inherit; color: #009999;">15</span><span class="p" style="box-sizing: inherit;">)</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">*</span> <span class="n" style="box-sizing: inherit;">unit</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">/</span> <span class="mi" style="box-sizing: inherit; color: #009999;">180</span>
</pre>
</div>
</div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="lazy-properties" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#lazy-properties" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>lazy properties</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
Swift2.2では遅延プロパティをタイプチェックし、<br />
ターゲット内のすべての単一の.swiftファイルの遅延プロパティのコンパイル時間は累積されます。Swift 3.0では、この問題は引き続き起こりますが、ビルド時間はほぼ半減しています。<br />
遅延プロパティを使用している場合は、注意を払うことをお勧めします。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">BadLazyProperties.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="n" style="box-sizing: inherit;">private</span><span class="p" style="box-sizing: inherit;">(</span><span class="kr" style="box-sizing: inherit; font-weight: 700;">set</span><span class="p" style="box-sizing: inherit;">)</span> <span class="n" style="box-sizing: inherit;">lazy</span> <span class="k" style="box-sizing: inherit; font-weight: 700;">var</span> <span class="nl" style="box-sizing: inherit;">chartViewColors</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">[</span><span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">]</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="p" style="box-sizing: inherit;">[</span>
<span class="nb" style="box-sizing: inherit; color: #0086b3;">self</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">chartColor</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">86</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">84</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">124</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">80</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">88</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">92</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">126</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">191</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">189</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">161</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">77</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">63</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">235</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">185</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">120</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">100</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">126</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">159</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">160</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">209</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">109</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="nb" style="box-sizing: inherit; color: #0086b3;">self</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">backgroundGradientView</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">upperColor</span>
<span class="p" style="box-sizing: inherit;">]</span>
</pre>
</div>
</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
ビルド時間を改善するには、できるだけプライベートメソッドにコードを移動</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: inherit; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: inherit;">GoodLazyProperties.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: inherit;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: inherit; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow-x: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Cumulative build time: 56.3ms</span>
<span class="n" style="box-sizing: inherit;">private</span><span class="p" style="box-sizing: inherit;">(</span><span class="kr" style="box-sizing: inherit; font-weight: 700;">set</span><span class="p" style="box-sizing: inherit;">)</span> <span class="n" style="box-sizing: inherit;">lazy</span> <span class="k" style="box-sizing: inherit; font-weight: 700;">var</span> <span class="nl" style="box-sizing: inherit;">chartViewColors</span><span class="p" style="box-sizing: inherit;">:</span> <span class="p" style="box-sizing: inherit;">[</span><span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">]</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">=</span> <span class="nb" style="box-sizing: inherit; color: #0086b3;">self</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">createChartViewColors</span><span class="p" style="box-sizing: inherit;">()</span>
<span class="c1" style="box-sizing: inherit; color: #999988; font-style: italic;">// Build time: 6.2ms</span>
<span class="n" style="box-sizing: inherit;">private</span> <span class="k" style="box-sizing: inherit; font-weight: 700;">func</span> <span class="n" style="box-sizing: inherit;">createChartViewColors</span><span class="p" style="box-sizing: inherit;">()</span> <span class="o" style="box-sizing: inherit; font-weight: 700;">-></span> <span class="p" style="box-sizing: inherit;">[</span><span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">]</span> <span class="p" style="box-sizing: inherit;">{</span>
<span class="k" style="box-sizing: inherit; font-weight: 700;">return</span> <span class="p" style="box-sizing: inherit;">[</span>
<span class="n" style="box-sizing: inherit;">chartColor</span><span class="p" style="box-sizing: inherit;">,</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">86</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">84</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">124</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">80</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">88</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">92</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">126</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">191</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">189</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">161</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">77</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">63</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">235</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">185</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">120</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">100</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">126</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">159</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="bp" style="box-sizing: inherit; color: #999999;">UIColor</span><span class="p" style="box-sizing: inherit;">(</span><span class="nl" style="box-sizing: inherit;">red</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">160</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">green</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">209</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">blue</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">109</span><span class="o" style="box-sizing: inherit; font-weight: 700;">/</span><span class="mi" style="box-sizing: inherit; color: #009999;">255</span><span class="p" style="box-sizing: inherit;">,</span> <span class="nl" style="box-sizing: inherit;">alpha</span><span class="p" style="box-sizing: inherit;">:</span> <span class="mi" style="box-sizing: inherit; color: #009999;">1</span><span class="p" style="box-sizing: inherit;">),</span>
<span class="n" style="box-sizing: inherit;">backgroundGradientView</span><span class="p" style="box-sizing: inherit;">.</span><span class="n" style="box-sizing: inherit;">upperColor</span>
<span class="p" style="box-sizing: inherit;">]</span>
<span class="p" style="box-sizing: inherit;">}</span>
</pre>
</div>
</div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
上記の遅延プロパティは繰り返しタイプチェックを受け取りますが、コードを移動するとビルド時間が96.7%短縮されます。<br />
参考: Swift build time optimizations — Part 2<br />
<a class="autolink" href="https://medium.com/swift-programming/swift-build-time-optimizations-part-2-37b0a7514cbe#.pshxh3hjo" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">https://medium.com/swift-programming/swift-build-time-optimizations-part-2-37b0a7514cbe#.pshxh3hjo</a></div>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="final-private-修飾子を付与" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#final-private-%E4%BF%AE%E9%A3%BE%E5%AD%90%E3%82%92%E4%BB%98%E4%B8%8E" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">final</code>, <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">private</code> 修飾子を付与</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
動的ディスパッチを減らすため(実行時のオーバーヘッドをなくし、パフォーマンスをあげる)<br />
継承しないクラス、メソッド、プロパティに関しては<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">final</code>, <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">private</code> 修飾子を付与<br />
間接実行ではなく直接実行するので速い</div>
<ul style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.7; list-style: none; margin: 1em 0px; padding: 0px 0px 0px 1.5em;">
<li style="box-sizing: inherit; list-style-type: disc;">overrideされることがなければ、直接実行されるので高速化</li>
<li style="box-sizing: inherit; list-style-type: disc;">適切に<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">public</code> <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">internal</code> <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">final</code> <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">private</code>を使い分ける</li>
</ul>
<h4 style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="struct-enumを使用" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#struct-enum%E3%82%92%E4%BD%BF%E7%94%A8" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">Struct</code>, <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">Enum</code>を使用</h4>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">Struct</code>は継承できず、直接実行なので速い<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">struct</code>と<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">enum</code>を組み合わせることで継承クラスのような振る舞いは可能<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">class</code>はヒープ領域に、<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: inherit; font-family: monospace, monospace; font-size: 0.9em; padding: 2px 4px;">struct</code>はスタック領域にメモリ確保されるので速い<br />
スタックはポインタ加算でメモリ確保、減算でメモリ破棄、シンプル<br />
ヒープは「空き」を探しメモリ確保する、その領域に再挿入することでメモリ破棄<br />
Heapは様々なスレッドからアクセスされるので「保護」する必要がある<br />
このコストは決して小さくはない</div>
<h2 style="border-bottom: 1px solid rgb(238, 238, 238); box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="最後に" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E6%9C%80%E5%BE%8C%E3%81%AB" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>最後に</h2>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
型推論をさせない点で言えば、静的な型定義は高速化のポイントになりますが、冗長になり可読性が落ちるということもありえますので、分析結果をみてパフォーマンスが悪い部分のみ、型宣言するのでもいいかもしれません。<br />
ビルド時間が遅いのはいらいらしますし、何よりコンパイラを混乱させないように、解釈しやすいようにコードを書くことはビルド時間の短縮、可読性を上げることにも繋がるのでおすすめです。Swift3.0でパフォーマンスが上がったことは間違いないですが、コンパイラにとって何が解釈しやすいかを調べることはこれからも重要でしょう。</div>
<h2 style="border-bottom: 1px solid rgb(238, 238, 238); box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="参考" style="box-sizing: inherit; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/e95f30023eccc8d96357/edit#%E5%8F%82%E8%80%83" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;"></a>参考</h2>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em;">
Profiling your Swift compilation times<br />
<a class="autolink" href="http://irace.me/swift-profiling" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">http://irace.me/swift-profiling</a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
Regarding Swift build time optimizations<br />
<a class="autolink" href="https://medium.com/@RobertGummesson/regarding-swift-build-time-optimizations-fc92cdd91e31#.fvpq4qkxw" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">https://medium.com/@RobertGummesson/regarding-swift-build-time-optimizations-fc92cdd91e31#.fvpq4qkxw</a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
XCode 8.0 Swift 3.0 slow indexing and building<br />
<a class="autolink" href="http://stackoverflow.com/questions/39547197/xcode-8-0-swift-3-0-slow-indexing-and-building" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">http://stackoverflow.com/questions/39547197/xcode-8-0-swift-3-0-slow-indexing-and-building</a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-bottom: 1.4em; margin-top: 1.4em;">
Swiftのメソッド毎のコンパイル時間を計測してビルド時間を短縮する<a class="autolink" href="http://qiita.com/rizumita/items/913b05d799b3712260f6" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;">http://qiita.com/rizumita/items/913b05d799b3712260f6</a></div>
<div style="box-sizing: inherit; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.4em;">
【Swift】 それ、enumとstructでやってみましょう!!<br />
<a class="autolink" href="http://www.slideshare.net/uin010/swift-enum" rel="nofollow noopener" style="background-color: transparent; box-sizing: inherit; color: #337ab7; text-decoration: none;" target="_blank">http://www.slideshare.net/uin010/swift-enum</a></div>
</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-73789082417500821122016-11-07T17:11:00.001+09:002016-11-07T17:11:27.200+09:00AWS IoTでM2Mことはじめ(iOS, Node.js)<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
AWS IoTでMQTTプロトコルを使用したNode.js, iOS(Swift)の疎通サンプルがあります。<br style="box-sizing: border-box;" />2016年11月現在動作確認済み。AWS IoT自体は昨年にリリースされて記事自体も昨年書いたものですが、備忘録として残しておきます。</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="amazon-iotってなに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#amazon-iot%E3%81%A3%E3%81%A6%E3%81%AA%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>Amazon IoTってなに?</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
ハードウェアをサポートするバックエンドの仕組みをAWSに素早く、簡単に構築できるクラウドサービス。インターネットに接続されたデバイスとデバイスをつなぎ、安全な双方向性通信を提供。</div>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.7; margin-bottom: 1em; margin-top: 1em; padding-left: 1.5em;">
<li style="box-sizing: border-box;">MQTT v3.1.1</li>
<li style="box-sizing: border-box;">QoS 0, 1に対応(2には対応していない)</li>
<li style="box-sizing: border-box;">Will, Retainに対応していない →Thing Shadowという状態を検知する仕組みがあるので不要ということ。</li>
<li style="box-sizing: border-box;">Payloadサイズ128KB</li>
<li style="box-sizing: border-box;">TLS対応</li>
<li style="box-sizing: border-box;">WebSocket、WebSecureSocket対応あり(2016/1/28のアップデートにて)<a class="autolink" href="https://aws.amazon.com/jp/about-aws/whats-new/2016/01/aws-iot-now-supports-websockets-custom-keepalive-intervals-and-enhanced-console/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">https://aws.amazon.com/jp/about-aws/whats-new/2016/01/aws-iot-now-supports-websockets-custom-keepalive-intervals-and-enhanced-console/</a></li>
<li style="box-sizing: border-box;">認証, AWSアカウントで</li>
</ul>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="プロトコルはmqtt" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E3%83%97%E3%83%AD%E3%83%88%E3%82%B3%E3%83%AB%E3%81%AFmqtt" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>プロトコルはMQTT</h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">TCP/IP 上で動作するpublish/subscribeモデルに基づく軽量なメッセージプロトコル。</li>
<li style="box-sizing: border-box;">軽量メッセージ配信に特化しており、センサーデータなどに使用される(M2M)、</li>
<li style="box-sizing: border-box;">Facebook MessengerもMQTT</li>
<li style="box-sizing: border-box;">256メガバイトが最大</li>
<li style="box-sizing: border-box;">固定長ヘッダーが最小2バイトとオーバーヘッドが少なく、またプロコトルも単純です。そのため、HTTPに比べるとネットワーク帯域および処理速度に優れています。また、処理が少ないということで、消費電力も少なくなっており、モバイル機器にも向いている</li>
</ul>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="キーワード" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E3%82%AD%E3%83%BC%E3%83%AF%E3%83%BC%E3%83%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>キーワード</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
Topic、QoS、Device gateway, Registry, Thing Shadow, Rules</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="getting-started" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#getting-started" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>Getting Started</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
まずはコンソール上でpub/sub</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="ossmqtt実装のmosquittoクライアントをインストール" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#ossmqtt%E5%AE%9F%E8%A3%85%E3%81%AEmosquitto%E3%82%AF%E3%83%A9%E3%82%A4%E3%82%A2%E3%83%B3%E3%83%88%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>OSS,MQTT実装のmosquittoクライアントをインストール</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">npm install mqtt</code></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="aws-cli-のアップグレード" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#aws-cli-%E3%81%AE%E3%82%A2%E3%83%83%E3%83%97%E3%82%B0%E3%83%AC%E3%83%BC%E3%83%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>AWS CLI のアップグレード</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
IoT Message Broker を操作するには AWS CLI 1.8.12 以上が必要<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">sudo pip install awscli --upgrade</code></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="認証関連" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E8%AA%8D%E8%A8%BC%E9%96%A2%E9%80%A3" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>認証関連</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
こちらに沿って<br style="box-sizing: border-box;" /><a class="autolink" href="http://docs.aws.amazon.com/iot/latest/developerguide/secure-communication.html" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://docs.aws.amazon.com/iot/latest/developerguide/secure-communication.html</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
cert.json というファイル名で保存<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">aws iot create-keys-and-certificate --set-as-active > cert.json</code></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
jqコマンドがなければ<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">brew install jq</code></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
各情報を保存<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">cat cert.json | jq .keyPair.PublicKey -r > thing-public-key.pem</code><br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">cat cert.json | jq .keyPair.PrivateKey -r > private-key.pem</code><br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">cat cert.json | jq .certificatePem -r > cert.pem</code></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
ルートCAをシマンテックサイトから取得<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">curl -o rootCA.pem https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem</code></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="iam-roleの設定" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#iam-role%E3%81%AE%E8%A8%AD%E5%AE%9A" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>IAM Roleの設定</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
MQTT ブローカーに pub/sub するための IAM Role を Certification に設定<br style="box-sizing: border-box;" />iot サービスを操作できる "PubSubToAnyTopic" という名前のポリシーを作成</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
以下jsonファイルを作成</div>
<div class="code-frame" data-lang="json" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: border-box;">policy.json</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"Version"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"2012-10-17"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"Statement"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">[{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"Effect"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"Allow"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"Action"</span><span class="p" style="box-sizing: border-box;">:[</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"iot:*"</span><span class="p" style="box-sizing: border-box;">],</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"Resource"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">[</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"*"</span><span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">}]</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
ポリシーをプリンシパルにひも付けます。 プリンシパルとなるのは aws iot create-keys-and-certificateコマンドを実行した時の certificateArn です<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">aws iot attach-principal-policy --principal "arn:aws:iot:ap-northeast-1:1111111:cert/SNIP" --policy-name "PubSubToAnyTopic"</code></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="準備完了" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E6%BA%96%E5%82%99%E5%AE%8C%E4%BA%86" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>準備完了</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
pub/sub通信が出来る状態となりました。</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="mqtt-エンドポイントの確認" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#mqtt-%E3%82%A8%E3%83%B3%E3%83%89%E3%83%9D%E3%82%A4%E3%83%B3%E3%83%88%E3%81%AE%E7%A2%BA%E8%AA%8D" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>MQTT エンドポイントの確認</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">aws iot describe-endpoint</code>でAWSアカウントごとに異なるエンドポイントの確認</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">$ aws iot describe-endpoint
{
"endpointAddress": "HOGE.iot. northeast-1.amazonaws.com"
}
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="subscribe" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#subscribe" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>Subscribe</h3>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">mosquitto_sub --cafile rootCA.pem --cert cert.pem --key private-key.pem -h "HOGE.iot.ap-northeast-1.amazonaws.com" -p 8883 -q 1 -d -t topic/test -i clientid1
Client clientid1 sending CONNECT
Client clientid1 received CONNACK
Client clientid1 sending SUBSCRIBE (Mid: 1, Topic: topic/test, QoS: 1)
Client clientid1 received SUBACK
Subscribed (mid: 1): 1
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="publish" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#publish" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>Publish</h3>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">mosquitto_pub --cafile rootCA.pem --cert cert.pem --key private-key.pem -h "HOGE.iot.ap-northeast-1.amazonaws.com" -p 8883 -q 1 -d -t topic/test -i clientid2 -m "Hello, World"
Client clientid2 sending CONNECT
Client clientid2 received CONNACK
Client clientid2 sending PUBLISH (d0, q1, r0, m1, 'topic/test', ... (12 bytes))
Client clientid2 received PUBACK (Mid: 1)
Client clientid2 sending DISCONNECT
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="確認" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E7%A2%BA%E8%AA%8D" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>確認</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
Subscribe側でHello, Worldの確認</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">Client clientid1 received PUBLISH (d0, q1, r0, m1, 'topic/test', ... (12 bytes))
Client clientid1 sending PUBACK (Mid: 1)
Hello, World
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
とpublishした後、メッセージが<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">Hello, World</code>と表示されていればOKです。</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="nodejsでやってみる" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#nodejs%E3%81%A7%E3%82%84%E3%81%A3%E3%81%A6%E3%81%BF%E3%82%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>Node.jsでやってみる</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
AWS IoT SDK for JavaScriptのインストール<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">npm install aws-iot-device-sdk</code></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
先ほどのmqtt.jsのラッパーでクライアントインスタンスを経由して、<br style="box-sizing: border-box;" />デバイスとAWS IoTをセキュアに接続します。mqttを意識することなく使えます。<br style="box-sizing: border-box;" />deviceクラスとthingShadowクラスがあります。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
詳細はこちら<br style="box-sizing: border-box;" /><a class="autolink" href="https://github.com/aws/aws-iot-device-sdk-js" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">https://github.com/aws/aws-iot-device-sdk-js</a></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="subscribe-1" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#subscribe-1" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>Subscribe</h3>
<div class="code-frame" data-lang="javascript" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: border-box;">deviceSub.js</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">awsIot</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">require</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'aws-iot-device-sdk'</span><span class="p" style="box-sizing: border-box;">);</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">fs</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">require</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'fs'</span><span class="p" style="box-sizing: border-box;">);</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 先ほど生成した認証ファイルを指定</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">KEY</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">__dirname</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">+</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'/private-key.pem'</span><span class="p" style="box-sizing: border-box;">;</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">CERT</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">__dirname</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">+</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'/cert.pem'</span><span class="p" style="box-sizing: border-box;">;</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">TRUSTED_CA</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">__dirname</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">+</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'/rootCA.pem'</span><span class="p" style="box-sizing: border-box;">;</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">device</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">awsIot</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">device</span><span class="p" style="box-sizing: border-box;">(</span>
<span class="p" style="box-sizing: border-box;">{</span>
<span class="nx" style="box-sizing: border-box;">keyPath</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="nx" style="box-sizing: border-box;">KEY</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nx" style="box-sizing: border-box;">certPath</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="nx" style="box-sizing: border-box;">CERT</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nx" style="box-sizing: border-box;">caPath</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="nx" style="box-sizing: border-box;">TRUSTED_CA</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nx" style="box-sizing: border-box;">clientId</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'clientid2'</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nx" style="box-sizing: border-box;">region</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'ap-northeast-1'</span>
<span class="p" style="box-sizing: border-box;">});</span>
<span class="nx" style="box-sizing: border-box;">device</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">on</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'connect'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kd" style="box-sizing: border-box; font-weight: 700;">function</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nx" style="box-sizing: border-box;">console</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">log</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'connect'</span><span class="p" style="box-sizing: border-box;">);</span>
<span class="nx" style="box-sizing: border-box;">device</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">subscribe</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'topic_1'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="p" style="box-sizing: border-box;">{</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'qos'</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1</span><span class="p" style="box-sizing: border-box;">});</span>
<span class="p" style="box-sizing: border-box;">});</span>
<span class="nx" style="box-sizing: border-box;">device</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">on</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'message'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kd" style="box-sizing: border-box; font-weight: 700;">function</span><span class="p" style="box-sizing: border-box;">(</span><span class="nx" style="box-sizing: border-box;">topic</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nx" style="box-sizing: border-box;">payload</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nx" style="box-sizing: border-box;">console</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">log</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'message'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nx" style="box-sizing: border-box;">topic</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nx" style="box-sizing: border-box;">payload</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">toString</span><span class="p" style="box-sizing: border-box;">());</span>
<span class="p" style="box-sizing: border-box;">});</span>
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="publish-1" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#publish-1" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>Publish</h3>
<div class="code-frame" data-lang="javascript" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: border-box;">devicePub.js</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">awsIot</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">require</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'aws-iot-device-sdk'</span><span class="p" style="box-sizing: border-box;">);</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">fs</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">require</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'fs'</span><span class="p" style="box-sizing: border-box;">);</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 先ほど生成した認証ファイルを指定</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">KEY</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">__dirname</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">+</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'/private-key.pem'</span><span class="p" style="box-sizing: border-box;">;</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">CERT</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">__dirname</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">+</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'/cert.pem'</span><span class="p" style="box-sizing: border-box;">;</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">TRUSTED_CA</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">__dirname</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">+</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'/rootCA.pem'</span><span class="p" style="box-sizing: border-box;">;</span>
<span class="kd" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nx" style="box-sizing: border-box;">device</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nx" style="box-sizing: border-box;">awsIot</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">device</span><span class="p" style="box-sizing: border-box;">(</span>
<span class="p" style="box-sizing: border-box;">{</span>
<span class="nx" style="box-sizing: border-box;">keyPath</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="nx" style="box-sizing: border-box;">KEY</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nx" style="box-sizing: border-box;">certPath</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="nx" style="box-sizing: border-box;">CERT</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nx" style="box-sizing: border-box;">caPath</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="nx" style="box-sizing: border-box;">TRUSTED_CA</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nx" style="box-sizing: border-box;">clientId</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'clientid2'</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nx" style="box-sizing: border-box;">region</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'ap-northeast-1'</span>
<span class="p" style="box-sizing: border-box;">});</span>
<span class="nx" style="box-sizing: border-box;">device</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">on</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'connect'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kd" style="box-sizing: border-box; font-weight: 700;">function</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nx" style="box-sizing: border-box;">console</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">log</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'connect'</span><span class="p" style="box-sizing: border-box;">);</span>
<span class="nx" style="box-sizing: border-box;">device</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">publish</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'topic_1'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="s1" style="box-sizing: border-box; color: #dd1144;">'Hello mqtt\n\n'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="p" style="box-sizing: border-box;">{</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'qos'</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1</span><span class="p" style="box-sizing: border-box;">});</span>
<span class="p" style="box-sizing: border-box;">});</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">node deviceSub.js</code>を立ち上げて、<br style="box-sizing: border-box;" />別画面で<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">node devicePub.js</code>を打つと、</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
Sub側で</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">connect
message topic_1 Hello mqtt
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
とmessegeが表示されていればOK</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="iosでやってみる" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#ios%E3%81%A7%E3%82%84%E3%81%A3%E3%81%A6%E3%81%BF%E3%82%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>iOSでやってみる</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
流れとしては、先ほど作成した証明書3つのプロジェクト内にコピーし、<br style="box-sizing: border-box;" />クライアントを利用して指定したトピックにpublishするものです。<br style="box-sizing: border-box;" />今回の例は、GPS情報(json)を送信と、ボタンアクションで文字列の送信を行います。</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="ios向けmqttクライアント" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#ios%E5%90%91%E3%81%91mqtt%E3%82%AF%E3%83%A9%E3%82%A4%E3%82%A2%E3%83%B3%E3%83%88" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>iOS向けMQTTクライアント</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
Swiftで書かれたMQTTクライアントMoscapsule<br style="box-sizing: border-box;" /><a class="autolink" href="https://github.com/flightonary/Moscapsule" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">https://github.com/flightonary/Moscapsule</a><br style="box-sizing: border-box;" />こちらを使うと X.509 形式の証明書を利用した MQTT 通信が行えます。OpenSSL-Universalも依存しているので、こちらも一緒にインポート。</div>
<div class="code-frame" data-lang="Podfile" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">use_frameworks!
target 'MQTTSample' do
pod 'Moscapsule', :git => 'https://github.com/flightonary/Moscapsule.git'
pod 'OpenSSL-Universal', '~> 1.0.1.l'
pod 'SwiftyJSON'
end
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="証明書のインポート" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E8%A8%BC%E6%98%8E%E6%9B%B8%E3%81%AE%E3%82%A4%E3%83%B3%E3%83%9D%E3%83%BC%E3%83%88" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>証明書のインポート</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
Xcodeプロジェクトに先ほど用意した証明書、Privateキーファイル、ルートCAファイルをインポートします。</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="iosからtopicに向けてpublish" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#ios%E3%81%8B%E3%82%89topic%E3%81%AB%E5%90%91%E3%81%91%E3%81%A6publish" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>iOSからTopicに向けてPublish</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
位置情報を利用するため、<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">Info.plist</code>に<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">NSLocationWhenInUseUsageDescription</code>を追加することを忘れずに。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: border-box;">ViewController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="k" style="box-sizing: border-box; font-weight: 700;">import</span> <span class="n" style="box-sizing: border-box;">UIKit</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">import</span> <span class="n" style="box-sizing: border-box;">Moscapsule</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">import</span> <span class="n" style="box-sizing: border-box;">SwiftyJSON</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">import</span> <span class="n" style="box-sizing: border-box;">CoreLocation</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">class</span> <span class="nl" style="box-sizing: border-box;">ViewController</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">UIViewController</span><span class="p" style="box-sizing: border-box;">,</span> <span class="bp" style="box-sizing: border-box; color: #999999;">CLLocationManagerDelegate</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nl" style="box-sizing: border-box;">manager</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">CLLocationManager</span><span class="o" style="box-sizing: border-box; font-weight: 700;">?</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nl" style="box-sizing: border-box;">mqttClient</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">MQTTClient</span><span class="o" style="box-sizing: border-box; font-weight: 700;">?</span>
<span class="p" style="box-sizing: border-box;">@</span><span class="kt" style="box-sizing: border-box; color: #445588; font-weight: 700;">IBOutlet</span> <span class="k" style="box-sizing: border-box; font-weight: 700;">weak</span> <span class="k" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nl" style="box-sizing: border-box;">latLb</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">UILabel</span><span class="o" style="box-sizing: border-box; font-weight: 700;">!</span>
<span class="p" style="box-sizing: border-box;">@</span><span class="kt" style="box-sizing: border-box; color: #445588; font-weight: 700;">IBOutlet</span> <span class="k" style="box-sizing: border-box; font-weight: 700;">weak</span> <span class="k" style="box-sizing: border-box; font-weight: 700;">var</span> <span class="nl" style="box-sizing: border-box;">lngLb</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">UILabel</span><span class="o" style="box-sizing: border-box; font-weight: 700;">!</span>
<span class="kr" style="box-sizing: border-box; font-weight: 700;">override</span> <span class="k" style="box-sizing: border-box; font-weight: 700;">func</span> <span class="n" style="box-sizing: border-box;">viewDidLoad</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">super</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">viewDidLoad</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="n" style="box-sizing: border-box;">initMQTTClient</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="n" style="box-sizing: border-box;">manager</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">CLLocationManager</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="n" style="box-sizing: border-box;">manager</span><span class="o" style="box-sizing: border-box; font-weight: 700;">?</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">delegate</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 「アプリ使用時のみ許可」でなかったら、ダイアログを出す。</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">if</span> <span class="bp" style="box-sizing: border-box; color: #999999;">CLLocationManager</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">authorizationStatus</span><span class="p" style="box-sizing: border-box;">()</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">!=</span> <span class="n" style="box-sizing: border-box;">CLAuthorizationStatus</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">AuthorizedWhenInUse</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">manager</span><span class="o" style="box-sizing: border-box; font-weight: 700;">?</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">requestWhenInUseAuthorization</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">manager</span><span class="o" style="box-sizing: border-box; font-weight: 700;">?</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">startUpdatingLocation</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">func</span> <span class="n" style="box-sizing: border-box;">locationManager</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">manager</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">CLLocationManager</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">didChangeAuthorizationStatus</span> <span class="nl" style="box-sizing: border-box;">status</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">CLAuthorizationStatus</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">if</span> <span class="n" style="box-sizing: border-box;">status</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">==</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">AuthorizedWhenInUse</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">manager</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">startUpdatingLocation</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 位置情報の更新で MQTT のトピックに送信</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">func</span> <span class="n" style="box-sizing: border-box;">locationManager</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">manager</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">CLLocationManager</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">didUpdateLocations</span> <span class="nl" style="box-sizing: border-box;">locations</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">[</span><span class="bp" style="box-sizing: border-box; color: #999999;">CLLocation</span><span class="p" style="box-sizing: border-box;">])</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">let</span> <span class="n" style="box-sizing: border-box;">location</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="n" style="box-sizing: border-box;">locations</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">first</span><span class="o" style="box-sizing: border-box; font-weight: 700;">!</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">let</span> <span class="nl" style="box-sizing: border-box;">json</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">JSON</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"state"</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"reported"</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"location"</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"latitude"</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="n" style="box-sizing: border-box;">location</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">coordinate</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">latitude</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"longitude"</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="n" style="box-sizing: border-box;">location</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">coordinate</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">longitude</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="n" style="box-sizing: border-box;">latLb</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">text</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="n" style="box-sizing: border-box;">location</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">coordinate</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">latitude</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">description</span>
<span class="n" style="box-sizing: border-box;">lngLb</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">text</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="n" style="box-sizing: border-box;">location</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">coordinate</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">longitude</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">description</span>
<span class="n" style="box-sizing: border-box;">publishTopic</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">json</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// MQTT クライアントの初期設定</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">func</span> <span class="n" style="box-sizing: border-box;">initMQTTClient</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">moscapsule_init</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">let</span> <span class="n" style="box-sizing: border-box;">mqttConfig</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="n" style="box-sizing: border-box;">MQTTConfig</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">clientId</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"server_cert_test"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nl" style="box-sizing: border-box;">host</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"HOGE.iot.ap-northeast-1.amazonaws.com"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">port</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">8883</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">keepAlive</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">60</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">let</span> <span class="n" style="box-sizing: border-box;">certFile</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSBundle</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">mainBundle</span><span class="p" style="box-sizing: border-box;">().</span><span class="n" style="box-sizing: border-box;">pathForResource</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"cert.pem"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">ofType</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"crt"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">let</span> <span class="n" style="box-sizing: border-box;">keyFile</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSBundle</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">mainBundle</span><span class="p" style="box-sizing: border-box;">().</span><span class="n" style="box-sizing: border-box;">pathForResource</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"private-key.pem"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">ofType</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"key"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">let</span> <span class="n" style="box-sizing: border-box;">caFile</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSBundle</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">mainBundle</span><span class="p" style="box-sizing: border-box;">().</span><span class="n" style="box-sizing: border-box;">pathForResource</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"rootCA"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">ofType</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"pem"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">mqttConfig</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">mqttServerCert</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="n" style="box-sizing: border-box;">MQTTServerCert</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">cafile</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">caFile</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">capath</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">mqttConfig</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">mqttClientCert</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="n" style="box-sizing: border-box;">MQTTClientCert</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">certfile</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">certFile</span><span class="o" style="box-sizing: border-box; font-weight: 700;">!</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">keyfile</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">keyFile</span><span class="o" style="box-sizing: border-box; font-weight: 700;">!</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">keyfile_passwd</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">mqttClient</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="n" style="box-sizing: border-box;">MQTT</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">newConnection</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">mqttConfig</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// トピックに向けた Publish</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">func</span> <span class="n" style="box-sizing: border-box;">publishTopic</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">json</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">JSON</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">let</span> <span class="n" style="box-sizing: border-box;">data</span> <span class="o" style="box-sizing: border-box; font-weight: 700;">=</span> <span class="n" style="box-sizing: border-box;">try</span><span class="o" style="box-sizing: border-box; font-weight: 700;">!</span> <span class="n" style="box-sizing: border-box;">json</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">rawData</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">mqttClient</span><span class="o" style="box-sizing: border-box; font-weight: 700;">!</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">publish</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">topic</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"topic_1"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">qos</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1</span><span class="p" style="box-sizing: border-box;">,</span> <span class="k" style="box-sizing: border-box; font-weight: 700;">retain</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// device shadowの場合、別途後述</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// self.mqttClient!.publish(data, topic: "$aws/things/iPhone-6/shadow/update", qos: 1, retain: false)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">@</span><span class="kt" style="box-sizing: border-box; color: #445588; font-weight: 700;">IBAction</span> <span class="k" style="box-sizing: border-box; font-weight: 700;">func</span> <span class="n" style="box-sizing: border-box;">pushPublish</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">sender</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">AnyObject</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">mqttClient</span><span class="o" style="box-sizing: border-box; font-weight: 700;">!</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">publishString</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"iOSからのpublish!!!"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">topic</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"topic_1"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">qos</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1</span><span class="p" style="box-sizing: border-box;">,</span> <span class="k" style="box-sizing: border-box; font-weight: 700;">retain</span><span class="o" style="box-sizing: border-box; font-weight: 700;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: 700;">func</span> <span class="n" style="box-sizing: border-box;">locationManager</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">manager</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">CLLocationManager</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">didFailWithError</span> <span class="nl" style="box-sizing: border-box;">error</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSError</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Failure"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="subscribe-2" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#subscribe-2" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>Subscribe</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
こちらはさきほどの<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">node deviceSub.js</code></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
で待ち受けていればOK</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="結果" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E7%B5%90%E6%9E%9C" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>結果</h3>
<h4 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="iosアプリから位置情報が更新されたら" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#ios%E3%82%A2%E3%83%97%E3%83%AA%E3%81%8B%E3%82%89%E4%BD%8D%E7%BD%AE%E6%83%85%E5%A0%B1%E3%81%8C%E6%9B%B4%E6%96%B0%E3%81%95%E3%82%8C%E3%81%9F%E3%82%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>iOSアプリから位置情報が更新されたら</h4>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">message topic_1
{
"state": {
"reported": {
"location": {
"longitude": 135.7848895,
"latitude": 35.0115832
}
}
}
}
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
pushPublishボタンアクションで</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">message topic_1 iOSからのpublish!!!
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
上記それぞれ表示されればOK</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="ここまではただのpubsub" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E3%81%93%E3%81%93%E3%81%BE%E3%81%A7%E3%81%AF%E3%81%9F%E3%81%A0%E3%81%AEpubsub" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>ここまではただのPub/Sub</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
ここまではただのMQTTブローカーです。</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="ここからが真骨頂-thing-shadows" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E3%81%93%E3%81%93%E3%81%8B%E3%82%89%E3%81%8C%E7%9C%9F%E9%AA%A8%E9%A0%82-thing-shadows" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>ここからが真骨頂 Thing Shadows</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
デバイスのことをThingと呼びます。<br style="box-sizing: border-box;" />Thing Shadow(デバイスの影像)はThingの状態がAWS上に存在するもの<br style="box-sizing: border-box;" />デバイスはオフラインになったり、状態が変更されるケースがあるので、アプリから管理するためにThing Shadowが存在する。永続的な仮想バージョンを作成できる。<br style="box-sizing: border-box;" />retainが不要なのは、Thing Shadowがあるから。<br style="box-sizing: border-box;" />retainというのは最後にPublishされたメッセージをMQTTサーバーが保持しておき、新しいSubscriberにそのメッセージを渡す機能<br style="box-sizing: border-box;" />ThingとThing Shadowは一対一で。Thingに変化があれば、Thing Shadowにも変更が通知される。<br style="box-sizing: border-box;" />reportedがThings、desiredがThing Shadowsの状態を示す</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="thing作成" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#thing%E4%BD%9C%E6%88%90" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>Thing作成</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
AWS CLIからも可能ですが、</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
①AWSコンソールから<a href="https://ap-northeast-1.console.aws.amazon.com/iot/home?region=ap-northeast-1#/dashboard" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">AWS IoT</a>を開きます<br style="box-sizing: border-box;" />②Resources横の <span style="box-sizing: border-box; font-weight: 700;">Create a Resource</span> を選択<br style="box-sizing: border-box;" />③パネルが展開されてCreate Thingを選択、Nameを入力後、Create<br style="box-sizing: border-box;" />④下のthings一覧から先ほど作成したthingを選択,右サイドパネルが展開されて、<br style="box-sizing: border-box;" /><span style="box-sizing: border-box; font-weight: 700;">Connect a device</span>を選択<br style="box-sizing: border-box;" />⑤Connect a deviceの画面でサポートするSDKの一覧から <span style="box-sizing: border-box; font-weight: 700;">NodeJS</span> を選択<br style="box-sizing: border-box;" />⑥ <span style="box-sizing: border-box; font-weight: 700;">Generate certificate and policy</span> を選択</div>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.7; margin-bottom: 1em; margin-top: 1em; padding-left: 1.5em;">
<li style="box-sizing: border-box;">Download public key</li>
<li style="box-sizing: border-box;">Download private key</li>
<li style="box-sizing: border-box;">Download certificate</li>
</ul>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
上記3つのファイルをダウンロード<br style="box-sizing: border-box;" />⑦ <span style="box-sizing: border-box; font-weight: 700;">Confirm & Start Connecting</span> を選択<br style="box-sizing: border-box;" />⑧以下のようなJSONが表示されるので。コピー</div>
<div class="code-frame" data-lang="json" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"host"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"HOGE.iot.ap-northeast-1.amazonaws.com"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"port"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">8883</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"clientId"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"hoge"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"thingName"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"hoge"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"caCert"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"root-CA.crt"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"clientCert"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"dca2683d89-certificate.pem.crt"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"privateKey"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"dca2683d89-private.pem.key"</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
⑨root-CA.crtというファイルをこちらのSymantecのページから取得<br style="box-sizing: border-box;" /><a class="autolink" href="https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
⑩ダウンロードした3つのファイル、JSON、root-CA.crtを同階層に置きます。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
これで準備で完了</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.3em; font-weight: 400; line-height: 1.43; margin: 3em 0px 0.7em;">
<span class="fragment" id="aws-cliでthing-shadow" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#aws-cli%E3%81%A7thing-shadow" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>AWS CLIでThing Shadow</h3>
<h4 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.2em; font-weight: 400; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="更新" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E6%9B%B4%E6%96%B0" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>更新</h4>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
デバイス <span style="box-sizing: border-box; font-weight: 700;">iPhone-6</span> の状態を初期登録<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">aws iot-data update-thing-shadow</code>コマンドで状態の更新<br style="box-sizing: border-box;" />ルート階層のstateは固定で、その下のreported以下に自由に要素を定義することができる。</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">$ aws iot-data update-thing-shadow --thing-name iPhone-6 --payload '{"state": {"reported" : {"power" : "off"}}}' outfile.json
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
レスポンスにはstateに加えてリクエストのバージョンとリクエストのタイムスタンプなどが付与されます。</div>
<div class="code-frame" data-lang="json" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: border-box;">outputfile.json</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"state"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"reported"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"off"</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"metadata"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"reported"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529567</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"version"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529567</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
パワーオンで更新</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">$ aws iot-data update-thing-shadow --thing-name iPhone-6 --payload '{"state": {"desired" : {"power" : "on"}}}' outfile2.json
</pre>
</div>
</div>
<div class="code-frame" data-lang="json" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: border-box;">outputfile2.json</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"state"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"desired"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"on"</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"metadata"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"desired"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529706</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"version"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">2</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529706</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
desiredがpower onになっています。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
状態情報の確認 <code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">aws iot-data get-thing-shadow</code>コマンドにて</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">$ aws iot-data get-thing-shadow --thing-name iPhone-6 outfile3.json
</pre>
</div>
</div>
<div class="code-frame" data-lang="json" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: border-box;">outputfile3.json</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"state"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"desired"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"on"</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"reported"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"off"</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"delta"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"on"</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"metadata"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"desired"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529706</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"reported"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529567</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"version"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">2</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529787</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
desired(thing shadow), reported(device)の状態で、<br style="box-sizing: border-box;" />deltaはstate.deltaにはデバイスの状態と望ましい状態の差分が抽出される。<br style="box-sizing: border-box;" />デバイス側でのパワーオン処理をしたと仮定して、パワーオンにしてみる。</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">$ aws iot-data update-thing-shadow --thing-name iPhone-6 --payload '{"state": {"reported" : {"power" : "on"}}}' outfile3.json
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
再度状態情報を確認</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">$ aws iot-data get-thing-shadow --thing-name iPhone-6 outfile4.json
</pre>
</div>
</div>
<div class="code-frame" data-lang="json" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 0.8em; line-height: 1; margin: 0px; padding: 0.25em 0.5em;">
<span class="bold" style="box-sizing: border-box;">outfile4.json</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"state"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"desired"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"on"</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"reported"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s2" style="box-sizing: border-box; color: #dd1144;">"on"</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"metadata"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"desired"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529706</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"reported"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"power"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529951</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">},</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"version"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">3</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nt" style="box-sizing: border-box; color: navy;">"timestamp"</span><span class="p" style="box-sizing: border-box;">:</span> <span class="mi" style="box-sizing: border-box; color: #009999;">1450529989</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
deltaが無くなり、差分が無くなっていることがわかる。<br style="box-sizing: border-box;" />versionは3となっているが、更新リクエストによってAWS側で自動でインクリメントされる。<br style="box-sizing: border-box;" />これは古いバージョンへ先祖還りを防いだり、他のpublisherによる更新を検知する手段となりうる。</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">$ aws iot-data update-thing-shadow --thing-name iPhone-6 --payload '{"state": {"reported" : {"power" : "on"}},"version" : 2}' outfile.json
A client error (ConflictException) occurred when calling the UpdateThingShadow operation: Version conflict
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
更新リクエストに"version" : 2の指定を入れたところ、既にバージョン3になっているため更新が拒否される</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
現在のバージョンの確認 jqで抜き出し</div>
<div class="code-frame" data-lang="text" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;">$ aws iot-data get-thing-shadow --thing-name iPhone-6 outfile4.json | cat outfile4.json | jq .version
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
3が出力される。</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="ルールの作成" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E3%83%AB%E3%83%BC%E3%83%AB%E3%81%AE%E4%BD%9C%E6%88%90" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>ルールの作成</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
①Create a rule、ルールの登録<br style="box-sizing: border-box;" />Rules Engineを通して必要なデータのみをフィルタリングしてデータのやり取りが可能<br style="box-sizing: border-box;" />queryをこのように<br style="box-sizing: border-box;" />SELECT * FROM 'topic_1'<br style="box-sizing: border-box;" />記述して</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
②<br style="box-sizing: border-box;" />topic_1にトピックを送信→S3にストアという流れを作ります。<br style="box-sizing: border-box;" />今回はS3にデータを送りたいので「Store the message in a file and store in the cloud (S3)」を選択して、Bucket等の設定を行います。<br style="box-sizing: border-box;" />iphone6-location-${timestamp()}<br style="box-sizing: border-box;" />で保存して、順次GPSデータが保存されていきます。<br style="box-sizing: border-box;" />${timestamp()}なしであれば、上書き保存します。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
正しくデータが送信されれば「iphone6」というファイルができているはず</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
AWS IoTを接続してS3にデータを送る一連の流れの説明</div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="おわりに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E3%81%8A%E3%82%8F%E3%82%8A%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>おわりに</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
AWS IoTでM2Mことはじめはこれで終わりです。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
実装のポイントとしては</div>
<blockquote style="background-color: white; border-left: 4px solid rgb(221, 221, 221); box-sizing: border-box; color: #555555; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; margin: 1em 0px 1em 0.8em; padding: 0.8em;">
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875;">
・ひとまず疎通確認のためにはS3への登録を選んでおいて、疎通確認後に本当に渡したいサービスを登録する<br style="box-sizing: border-box;" />・AWS IoTはQoS(Quality of Service)レベルの2が選択できないので複数投げられてもデータが重複しないような冪等性を確保した設計にするとよい<br style="box-sizing: border-box;" />・連続したデータはTopicにMQTTデータを投げる形で実装し、単発データや選択データ(ランプがつく/消える、や電話をかける、等)はSHADOWSで管理したほうがよい<br style="box-sizing: border-box;" />となります。入力部、出力部のデバイスの実装はなるべくシンプルにし、難しい処理はAWS内で片付けたほうが変更に強い実装ができます。例えばデータの丸め等はデバイス部では行わず、AWS IoTからLambda等を繋いでそこで行ったほうがよいです<br style="box-sizing: border-box;" />(<a class="autolink" href="http://dev.classmethod.jp/cloud/aws/cm-advent-calendar-2015-getting-started-again-iot/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://dev.classmethod.jp/cloud/aws/cm-advent-calendar-2015-getting-started-again-iot/</a>)</div>
</blockquote>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
things shadowの状態を監視して、他のデバイスを動かすという展開が考えられます。<br style="box-sizing: border-box;" /><a class="autolink" href="http://dev.classmethod.jp/cloud/update-device-shadow-by-lambda/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://dev.classmethod.jp/cloud/update-device-shadow-by-lambda/</a></div>
<h2 style="background-color: white; border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 1.6em; font-weight: 400; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="参考" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/c6bd694b0c7f26dd816a#%E5%8F%82%E8%80%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;"></a>参考</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875;">
MQTTについてのまとめ<br style="box-sizing: border-box;" /><a class="autolink" href="http://tdoc.info/blog/2014/01/27/mqtt.html" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://tdoc.info/blog/2014/01/27/mqtt.html</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
AWS IoT Message BrokerのMQTTでpub/subをやってみた #reinvent<br style="box-sizing: border-box;" /><a class="autolink" href="http://dev.classmethod.jp/cloud/aws/pub-sub-with-aws-iot-over-mqtt/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://dev.classmethod.jp/cloud/aws/pub-sub-with-aws-iot-over-mqtt/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
AWS IoTとRuby製MQTTクライアントでPub/Subしてみた<br style="box-sizing: border-box;" /><a class="autolink" href="http://qiita.com/hiroeorz@github/items/f933ad1158a08506922a" id="reference-144e2a12dd6624a362f8" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;">http://qiita.com/hiroeorz@github/items/f933ad1158a08506922a</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
Message Broker for AWS IoT (Beta)<br style="box-sizing: border-box;" /><a class="autolink" href="http://docs.aws.amazon.com/iot/latest/developerguide/iot-message-broker.html" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://docs.aws.amazon.com/iot/latest/developerguide/iot-message-broker.html</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
AWS IoT SDK for JavaScript<br style="box-sizing: border-box;" /><a class="autolink" href="https://github.com/aws/aws-iot-device-sdk-js" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">https://github.com/aws/aws-iot-device-sdk-js</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
The MQTT client for Node.js and the browser<br style="box-sizing: border-box;" /><a class="autolink" href="https://github.com/mqttjs/MQTT.js" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">https://github.com/mqttjs/MQTT.js</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
AWS IoT の Device Shadow を iOS アプリから MQTT で使ってみた #reinvent<br style="box-sizing: border-box;" /><a class="autolink" href="http://dev.classmethod.jp/cloud/aws/aws-iot-mqtt/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://dev.classmethod.jp/cloud/aws/aws-iot-mqtt/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
AWS IoTおよびThing Shadowsに関する雑感<br style="box-sizing: border-box;" /><a class="autolink" href="http://tdoc.info/blog/2015/10/09/thing_shadows.html" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://tdoc.info/blog/2015/10/09/thing_shadows.html</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
AWS IoTのThing Shadowsを図と実行例で理解する #reinvent<br style="box-sizing: border-box;" /><a class="autolink" href="http://dev.classmethod.jp/cloud/aws-iot-things-shadow/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://dev.classmethod.jp/cloud/aws-iot-things-shadow/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
これからAWSを使ってIoTをやってみたい人が抑えておくべき10のキーサービス & 7つのキーワード #reinvent<br style="box-sizing: border-box;" /><a class="autolink" href="http://dev.classmethod.jp/cloud/aws/aws-key-service-people-wanted-to-do-iot-should-study/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://dev.classmethod.jp/cloud/aws/aws-key-service-people-wanted-to-do-iot-should-study/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
AWS IoTのいろいろなルールを見てみる&ちょっと試してみる #reinvent<br style="box-sizing: border-box;" /><a class="autolink" href="http://dev.classmethod.jp/cloud/aws-iot-rules/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://dev.classmethod.jp/cloud/aws-iot-rules/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", メイリオ, meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em;">
【新機能】AWS IoT のRules EngineがAmazon machine Learningをサポート。IoTと機械学習が一体に<br style="box-sizing: border-box;" /><a class="autolink" href="http://dev.classmethod.jp/cloud/aws/aws-iot-supports-integration-with-amazon-machine-learning/" rel="nofollow noopener" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none;" target="_blank">http://dev.classmethod.jp/cloud/aws/aws-iot-supports-integration-with-amazon-machine-learning/</a></div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-75134955939499330322016-09-06T08:30:00.000+09:002016-09-06T09:00:20.990+09:00ウェブリオ株式会社様のAI英会話ナンナのアプリをお手伝いさせていただきました。<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; word-wrap: break-word;">
ウェブリオ株式会社様のAI英会話ナンナのアプリをお手伝いさせていただきました。<br />
担当はアプリ内の実装すべてです。<br />
好きな時間に好きな場所でいつでもナンナと英会話し放題です。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/b4d928b8-2a0b-3b69-b002-ebfd9836e286.png" rel="nofollow" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="AI-Nanna.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/b4d928b8-2a0b-3b69-b002-ebfd9836e286.png" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="AI-Nanna.png" /></a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
以下AppStoreより引用<br />
・モデル回答機能を使えば、スピーキングの採点が可能です。また、英会話の色々な場面における適切なフレーズを知ることができます。<br />
・スクリプトを非表示にすれば、音声のみでよりリアルな英会話をすることもできます。<br />
・レッスンをクリアしていく毎に、次のレベルのレッスンが解除していくシステムとなっています。<br />
・フリートークモードにすれば、レッスンとは一味違った自由な英会話をすることができます。<br />
・現在、無料でご利用することが可能なので、何回でも話し放題です。<br />
・レッスン1回あたりの時間はたったの2分なので、スキマ時間にも勉強できます。<br />
・予約不要で英会話レッスンができます。<br /><br />現状シンプルな機能に絞られていますが、今後追加の機能など開発していく予定です。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 1.6em; font-weight: normal; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="ダウンロードはこちら" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span>
ダウンロードはこちら</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; word-wrap: break-word;">
<a href="https://itunes.apple.com/jp/app/ying-hui-huaapuri-ai-ying/id1127756780?mt=8" style="background: url("https://linkmaker.itunes.apple.com/images/badges/en-us/badge_appstore-lrg.svg") no-repeat; display: inline-block; height: 40px; overflow: hidden; width: 165px;"></a>
</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 1.6em; font-weight: normal; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em;">
<span class="fragment" id="その他プレスリリース" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/fbd3dcf49afe219c0e78#%E3%81%9D%E3%81%AE%E4%BB%96%E3%83%97%E3%83%AC%E3%82%B9%E3%83%AA%E3%83%AA%E3%83%BC%E3%82%B9" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>その他プレスリリース</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; word-wrap: break-word;">
【Weblio公式】正しい文法で正確な英会話が身につく!AI(人工知能)英会話アプリをリリース<br />
<a class="autolink" href="https://www.weblio-inc.jp/wordpress/blog/2016/08/26/ai_app_release/" rel="nofollow" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank">https://www.weblio-inc.jp/wordpress/blog/2016/08/26/ai_app_release/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
【EdTech Media】ウェブリオ、AI(人工知能)英会話アプリをリリース<br />
<a class="autolink" href="http://edtech-media.com/2016/08/26/weblioai/?utm_source=dlvr.it&utm_medium=twitter" rel="nofollow" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank">http://edtech-media.com/2016/08/26/weblioai/?utm_source=dlvr.it&utm_medium=twitter</a></div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-20081223504679337092016-07-06T21:41:00.003+09:002016-07-06T21:41:32.966+09:00Swiftでランダム英数字の文字列生成(※arc4random()は使ってはいけない)<section class="markdownContent markdownContent-headingEnabled js-task-list-container clearfix position-relative js-task-list-enabled" id="item-50bcc149162d64b89b84" itemprop="articleBody" style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 1.15em; word-wrap: break-word;"><div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
SwiftでセッションIDなどのランダム英数字を生成させたい時</div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: inherit; font-size: 1.6em; font-weight: normal; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em; position: relative;">
<span class="fragment" id="ポイント" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/50bcc149162d64b89b84#%E3%83%9D%E3%82%A4%E3%83%B3%E3%83%88" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>ポイント</h2>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">arc4random()</code>ではなく、<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">arc4random_uniform(UInt32)</code>を使用するのがポイント</div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: inherit; font-size: 1.6em; font-weight: normal; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em; position: relative;">
<span class="fragment" id="arc4randomを使うとクラッシュする" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/50bcc149162d64b89b84#arc4random%E3%82%92%E4%BD%BF%E3%81%86%E3%81%A8%E3%82%AF%E3%83%A9%E3%83%83%E3%82%B7%E3%83%A5%E3%81%99%E3%82%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>arc4random()を使うとクラッシュする</h2>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">arc4random()</code>は乱数を生成させる関数ですが、Intにキャストする際に32bit端末ではクラッシュします。iPhone5や4Sなど、初代iPad Air以前は32bit</div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">arc4random</code>はunsigned 32 bit integerを返しますが、つまり0から4,294,967,295まで。<br style="box-sizing: border-box;" />IntはiPhone5で32ビットの整数と5S上の64ビット整数です。<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">arc4random()</code>はiPhone5上のIntの倍の正の範囲を持っているUInt32型を返すので、クラッシュする可能性が50%あります。</div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
また詳細は記述しませんが、ランダム性に少しバイアスがあるarc4random()のずれを補正し、int型に変換しても安全なのがarc4random_uniform()です。</div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: inherit; font-size: 1.6em; font-weight: normal; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em; position: relative;">
<span class="fragment" id="実装" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/50bcc149162d64b89b84#%E5%AE%9F%E8%A3%85" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>実装</h2>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
引数の数だけ、a-zの小文字大文字、0-9を組み合わせた文字列を生成します。<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14.49px; padding: 2px 4px;">arc4random_uniform</code>を使用</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">generate</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">length</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">Int</span><span class="p" style="box-sizing: border-box;">)</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">-></span> <span class="n" style="box-sizing: border-box;">String</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">base</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">randomString</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">String</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">""</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">for</span> <span class="n" style="box-sizing: border-box;">_</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span> <span class="mf" style="box-sizing: border-box; color: #009999;">0.</span><span class="p" style="box-sizing: border-box;">.</span><span class="o" style="box-sizing: border-box; font-weight: bold;"><</span><span class="n" style="box-sizing: border-box;">length</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">randomValue</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">arc4random_uniform</span><span class="p" style="box-sizing: border-box;">(</span><span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">UInt32</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">base</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">characters</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">count</span><span class="p" style="box-sizing: border-box;">))</span>
<span class="n" style="box-sizing: border-box;">randomString</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">+=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"\(base[base.startIndex.advancedBy(Int(randomValue))])"</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="n" style="box-sizing: border-box;">randomString</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: inherit; font-size: 1.6em; font-weight: normal; line-height: 1.225; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em; position: relative;">
<span class="fragment" id="参照" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/50bcc149162d64b89b84#%E5%8F%82%E7%85%A7" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>参照</h2>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
Generate random alphanumeric string in Swift<br style="box-sizing: border-box;" /><a class="autolink" href="http://stackoverflow.com/questions/26845307/generate-random-alphanumeric-string-in-swift" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://stackoverflow.com/questions/26845307/generate-random-alphanumeric-string-in-swift</a></div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
Objective-Cの乱数作成はarc4random_uniform<br style="box-sizing: border-box;" /><a class="autolink" href="http://tanukichi566.blog.fc2.com/blog-entry-57.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://tanukichi566.blog.fc2.com/blog-entry-57.html</a></div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
arc4randomの罠<br style="box-sizing: border-box;" /><a class="autolink" href="http://qiita.com/jtemplej/items/abebac88f930f9345f95" id="reference-55c51f0517ae790d326e" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://qiita.com/jtemplej/items/abebac88f930f9345f95</a></div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
[Swift][iOS]64bit対応におけるarc4random()について<br style="box-sizing: border-box;" /><a class="autolink" href="http://qiita.com/kiguchi/items/c75d6d3da05b3e8d80d9" id="reference-41526699ab6ec9d0e1a3" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://qiita.com/kiguchi/items/c75d6d3da05b3e8d80d9</a></div>
</section><br />you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-72422821114642648462016-07-03T21:37:00.001+09:002016-07-03T21:37:40.482+09:00Swiftで半角英字のValidation(英字ニックネームなど)<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; word-wrap: break-word;">
半角アルファベットのみで入力させたい場合のバリデーション</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"><span class="k" style="box-sizing: border-box; font-weight: bold;">extension</span> <span class="n" style="box-sizing: border-box;">String</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">isAllHalfWidthCharacter</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">Bool</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 半角も全角も1文字でカウント</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">nsStringlen</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">characters</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">count</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">utf8</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">(</span><span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSString</span><span class="p" style="box-sizing: border-box;">).</span><span class="n" style="box-sizing: border-box;">UTF8String</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// Cのstrlenは全角を2で判定する</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">cStringlen</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">Int</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">bitPattern</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">strlen</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">utf8</span><span class="p" style="box-sizing: border-box;">))</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">nsStringlen</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">==</span> <span class="n" style="box-sizing: border-box;">cStringlen</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">isValidNickName</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">Bool</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">rangeOfCharacterFromSet</span><span class="p" style="box-sizing: border-box;">(.</span><span class="n" style="box-sizing: border-box;">letterCharacterSet</span><span class="p" style="box-sizing: border-box;">(),</span> <span class="nl" style="box-sizing: border-box;">options</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">LiteralSearch</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">range</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">)</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">==</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span> <span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">rangeOfCharacterFromSet</span><span class="p" style="box-sizing: border-box;">(.</span><span class="n" style="box-sizing: border-box;">decimalDigitCharacterSet</span><span class="p" style="box-sizing: border-box;">(),</span> <span class="nl" style="box-sizing: border-box;">options</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">LiteralSearch</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">range</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">)</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">!=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span> <span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">guard</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">isAllHalfWidthCharacter</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">else</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span> <span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 1.7em; font-weight: normal; line-height: 1.2; margin: 2.5em 0px 0.5em; padding-bottom: 0.3em; position: relative;">
<span class="fragment" id="実用例" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/8c50530f5ba8584d178e#%E5%AE%9F%E7%94%A8%E4%BE%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>実用例</h1>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; word-wrap: break-word;">
isValidNickNameでチェック</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 0; margin: 1em 0px; overflow: hidden;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 0.8em; line-height: 1.2; overflow: auto; padding: 0.6em 1.2em; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">nickname</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">isValidNickName</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// Set Data</span>
<span class="p" style="box-sizing: border-box;">}</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">else</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// Alert</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">alertController</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">UIAlertController</span><span class="p" style="box-sizing: border-box;">(</span>
<span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"半角英字のみで入力してください"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nl" style="box-sizing: border-box;">message</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">""</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nl" style="box-sizing: border-box;">preferredStyle</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Alert</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">otherAction</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">UIAlertAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"OK"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">style</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Default</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">action</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">navigationController</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">popToViewController</span><span class="p" style="box-sizing: border-box;">(</span><span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">navigationController</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">viewControllers</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #009999;">0</span><span class="p" style="box-sizing: border-box;">],</span> <span class="nl" style="box-sizing: border-box;">animated</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">alertController</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">addAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">otherAction</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">presentViewController</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">alertController</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">animated</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">completion</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: "Helvetica Neue", Helvetica, "ヒラギノ角ゴ ProN W3", "Hiragino Kaku Gothic ProN", メイリオ, Meiryo, sans-serif; font-size: 16.1px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
NSStringではlengthでカウントできるのに、<br style="box-sizing: border-box;" />String型ではcharacters.countって長い</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-54682967247406978952016-03-21T00:46:00.003+09:002016-03-21T01:00:37.712+09:002016 Spring. Flying drone<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_e-ONBnji8PXh_pT16vg0CAdh-kHlUnrnTO7OPhtN_QHdhhUyi0xVtDIYizTJW1kC9mV3lhyV7RYDxGog69ah-T7HgwgrKuwQY2cK7_L18f-Lfw0-YdjG2DlJGDuTmYONZabAK25-lV4/s1600/DSCF5853.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_e-ONBnji8PXh_pT16vg0CAdh-kHlUnrnTO7OPhtN_QHdhhUyi0xVtDIYizTJW1kC9mV3lhyV7RYDxGog69ah-T7HgwgrKuwQY2cK7_L18f-Lfw0-YdjG2DlJGDuTmYONZabAK25-lV4/s640/DSCF5853.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv-iFuKpq3-11_SJBdL-FxKSKUbXVpujYUItx1_RJpBrLLW_mV0hLYxw6V0ZectSjtWvyGt7D8t6HmYS3YZNXUWzcXK8pfiNSk15d9cXCVg87oV_fvjqB_ZLMQkHB5uic1hhZQlAujaPQ/s1600/DSCF5856.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjv-iFuKpq3-11_SJBdL-FxKSKUbXVpujYUItx1_RJpBrLLW_mV0hLYxw6V0ZectSjtWvyGt7D8t6HmYS3YZNXUWzcXK8pfiNSk15d9cXCVg87oV_fvjqB_ZLMQkHB5uic1hhZQlAujaPQ/s640/DSCF5856.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxc4zhNsQijg4FBYcXpoV2sw10CGVpDPP8F_yhMquCfw6vqm_EqxAJUxqoQcwLnpCQh4qbHKJfVTZj2lDHZ3Ux2lxympaiorfrUvrGKiSq_vLR17kk9TOEqo3thNqh6z2dn5diaiNMKg4/s1600/DSCF5857.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxc4zhNsQijg4FBYcXpoV2sw10CGVpDPP8F_yhMquCfw6vqm_EqxAJUxqoQcwLnpCQh4qbHKJfVTZj2lDHZ3Ux2lxympaiorfrUvrGKiSq_vLR17kk9TOEqo3thNqh6z2dn5diaiNMKg4/s640/DSCF5857.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDhdcqbi_z3lNtZdjcwO435VGgjbMo6iloo-m4nfLrXToo9xJjTD4pBJ61zLe4-_e90r8lGPpfY_qt_Ntdx16caMho2bD-7mAVp3l73UBlq4R-zlVnR9MqyvoXnh9HEhNEDM-cVl-2lFA/s1600/DSCF5858.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDhdcqbi_z3lNtZdjcwO435VGgjbMo6iloo-m4nfLrXToo9xJjTD4pBJ61zLe4-_e90r8lGPpfY_qt_Ntdx16caMho2bD-7mAVp3l73UBlq4R-zlVnR9MqyvoXnh9HEhNEDM-cVl-2lFA/s640/DSCF5858.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQYEBBo__2QhP_TTr4jTQFq0dYdWtRFa1pliGGr9Pp1VYeNnmYhXIjhMAyREcbZmwnyVIGEYPn1V2sdq9FICG5Tfma9mlzuP1Q497fdcoylpxMOgoIuK_eJd4_W0vNOI0XjNsHhP1pMOU/s1600/DSCF5859.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQYEBBo__2QhP_TTr4jTQFq0dYdWtRFa1pliGGr9Pp1VYeNnmYhXIjhMAyREcbZmwnyVIGEYPn1V2sdq9FICG5Tfma9mlzuP1Q497fdcoylpxMOgoIuK_eJd4_W0vNOI0XjNsHhP1pMOU/s640/DSCF5859.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhevXlOz5_Sx5XZXBv_Q71lYdFJZKQ_cxVHdHHmgTpLrwMQem3Rm7A3w1Oo3USC8k-0GzekSRwIwuTL-KeXVh6q7DKKnBSFH5sRStOkd8J9UT7KLjPP0kZZYo-dYYiQPf-ZQvfQTketR88/s1600/DSCF5860.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhevXlOz5_Sx5XZXBv_Q71lYdFJZKQ_cxVHdHHmgTpLrwMQem3Rm7A3w1Oo3USC8k-0GzekSRwIwuTL-KeXVh6q7DKKnBSFH5sRStOkd8J9UT7KLjPP0kZZYo-dYYiQPf-ZQvfQTketR88/s640/DSCF5860.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTtxvmhGrk1xJEl3Xxhh4Ygd29yjzhOvTZL-wkpYf7XkHRhcvQpWXfSF0ICz_Uj4xRbvpqk8XLeW0CimQlVzbVjzsTbbfB5EQxw6WooQgw5cbQI6rwAg3Z43lIEOtunpJgVe3IAxfcrI4/s1600/DSCF5861.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTtxvmhGrk1xJEl3Xxhh4Ygd29yjzhOvTZL-wkpYf7XkHRhcvQpWXfSF0ICz_Uj4xRbvpqk8XLeW0CimQlVzbVjzsTbbfB5EQxw6WooQgw5cbQI6rwAg3Z43lIEOtunpJgVe3IAxfcrI4/s640/DSCF5861.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkZp4QIn_mata-AerM9AHOw2MgrV2lIn-SfB-6SeLxZ6MRxmeBJ9uCjJQUXDm_xHgmqKS-4BYvTsnL1YB9nqRGkp1I-Rk6wtTcgy5GNf1ocwoDzV5J9z-XKwF7PRviJyMFnO_gF43c_a4/s1600/DSCF5862.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkZp4QIn_mata-AerM9AHOw2MgrV2lIn-SfB-6SeLxZ6MRxmeBJ9uCjJQUXDm_xHgmqKS-4BYvTsnL1YB9nqRGkp1I-Rk6wtTcgy5GNf1ocwoDzV5J9z-XKwF7PRviJyMFnO_gF43c_a4/s640/DSCF5862.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ5CUgKkKF1EQIHBVQiNbZkYTk6dPXc1qHX71IOQCvM47bvOGIwk_DXmmxgema7zgzuu4DQ7T3FMgLZWYwn1SC359XLxFfWriaJTiNo3QT3pYW-9r7cP5QgZgqZGaPNvqT_BE2NtR_Ae8/s1600/DSCF5863.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ5CUgKkKF1EQIHBVQiNbZkYTk6dPXc1qHX71IOQCvM47bvOGIwk_DXmmxgema7zgzuu4DQ7T3FMgLZWYwn1SC359XLxFfWriaJTiNo3QT3pYW-9r7cP5QgZgqZGaPNvqT_BE2NtR_Ae8/s640/DSCF5863.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvUV1ivSE59lcCm0jEgIkCm6PQaeyAVQXubOjTixd0JyNUEXBM_ptfXGUKyj0vjobkg6sjfHCwp6hjvIDbLIcy_EBLSD_J0NamVR5lOAqewpeIScjfsfKkuziDUSXVt_xhGLRsz3OA8tc/s1600/DSCF5865.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvUV1ivSE59lcCm0jEgIkCm6PQaeyAVQXubOjTixd0JyNUEXBM_ptfXGUKyj0vjobkg6sjfHCwp6hjvIDbLIcy_EBLSD_J0NamVR5lOAqewpeIScjfsfKkuziDUSXVt_xhGLRsz3OA8tc/s640/DSCF5865.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnw58Sz_QdgP_dm6waonKOz649WE6Xp_yY3fSsRe82lQy5TDA2-BEhXDj2H7qr5Dt3B37Iz2Gd1_S4_MoPa5a_mA8dm2EYwR42HNVjtv6VXTMNC-R3EhEPImvpZdBzG5a9X9A0YzyEshE/s1600/DSCF5866.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnw58Sz_QdgP_dm6waonKOz649WE6Xp_yY3fSsRe82lQy5TDA2-BEhXDj2H7qr5Dt3B37Iz2Gd1_S4_MoPa5a_mA8dm2EYwR42HNVjtv6VXTMNC-R3EhEPImvpZdBzG5a9X9A0YzyEshE/s640/DSCF5866.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2lTodD9crcUzDAaf3IbMQCRbqluIdDTGklr2vLwFdmCunGmd0CtV7XWZ_8wMuXzrttdyP-hvvqQqZ8ZbhuydKjuRe-WVSF73vtn4Zkid-jIKd3Z0VEer35MOnC2g0Fm0bY87PPQQW6vk/s1600/DSCF5867.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2lTodD9crcUzDAaf3IbMQCRbqluIdDTGklr2vLwFdmCunGmd0CtV7XWZ_8wMuXzrttdyP-hvvqQqZ8ZbhuydKjuRe-WVSF73vtn4Zkid-jIKd3Z0VEer35MOnC2g0Fm0bY87PPQQW6vk/s640/DSCF5867.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNxWY1fb94rhNY6zzsT4Y7rUUQy2_Tj3lHea1sewGonaskSdMiStfgvmRdI8RO8sK9GdXvaPRXdgcMjhXqOo-mS3wPz17cA53pu_O4Rth9pUbQ-TAcPQLMWdMlMBEV61gGmyioW_rY-es/s1600/DSCF5868.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNxWY1fb94rhNY6zzsT4Y7rUUQy2_Tj3lHea1sewGonaskSdMiStfgvmRdI8RO8sK9GdXvaPRXdgcMjhXqOo-mS3wPz17cA53pu_O4Rth9pUbQ-TAcPQLMWdMlMBEV61gGmyioW_rY-es/s640/DSCF5868.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7x2W2ajSis3E0YAv-QbK2oPKOgRi2xRb2CgOWQBvprOW7Kosqxrgxfhsvj6C6NeJdJqck2m_ht-FEEypDdRLmbMEmU2gvp9inzh04QPPGxHIZZclsNdRLln1Y7NS3I3pxEGKEt-s2L1Y/s1600/DSCF5869.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7x2W2ajSis3E0YAv-QbK2oPKOgRi2xRb2CgOWQBvprOW7Kosqxrgxfhsvj6C6NeJdJqck2m_ht-FEEypDdRLmbMEmU2gvp9inzh04QPPGxHIZZclsNdRLln1Y7NS3I3pxEGKEt-s2L1Y/s640/DSCF5869.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZWPj8Z4c0hZyfTUo62anQGhIN7EuIPlnRvV7ND5NQvl2xTDhJSzyP-5oOJ58aWtZXH1w-RXUlV61qFXJPCMurByyi50yhfM3EvAVRBYQ_c65fOttF1wtTnjAHexmYh0BK4Q8KZjrvSxc/s1600/DSCF5870.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZWPj8Z4c0hZyfTUo62anQGhIN7EuIPlnRvV7ND5NQvl2xTDhJSzyP-5oOJ58aWtZXH1w-RXUlV61qFXJPCMurByyi50yhfM3EvAVRBYQ_c65fOttF1wtTnjAHexmYh0BK4Q8KZjrvSxc/s640/DSCF5870.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8qLmc12jErjhaq-hQcZmS9KV0MxZcfEg7uDNWr6RrlEzWTKUn3WKWbZoCMJ47NeA1PDkI1OLBe-YSz9HXgBGJm8GgGBW0lWBXmuT_NeNGjTWISMpBHcDe30vzZrmfGC23j9CwjFMdvEA/s1600/DSCF5871.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8qLmc12jErjhaq-hQcZmS9KV0MxZcfEg7uDNWr6RrlEzWTKUn3WKWbZoCMJ47NeA1PDkI1OLBe-YSz9HXgBGJm8GgGBW0lWBXmuT_NeNGjTWISMpBHcDe30vzZrmfGC23j9CwjFMdvEA/s640/DSCF5871.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUBhWaHRyMecm1rMzNRKcIJMnhkNtyZQMmB_FIGQ_-MTlDvKIQ_9ZATBD8PSsXJNAEmxNhy7LHS6mS2UetO00bnHPy70LEkQOqFzZre_Hwgf_RH8yelbiFXJTQy9l8nqMq5ySroM53t_8/s1600/DSCF5875.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUBhWaHRyMecm1rMzNRKcIJMnhkNtyZQMmB_FIGQ_-MTlDvKIQ_9ZATBD8PSsXJNAEmxNhy7LHS6mS2UetO00bnHPy70LEkQOqFzZre_Hwgf_RH8yelbiFXJTQy9l8nqMq5ySroM53t_8/s640/DSCF5875.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig6NmUq14HrQDlSlwCk2Edu2sWMnSAiCUOlUZYIQhPyHhavo9d8ElXzf_KGe3DDysao2HuR_3W7W3goKkNzOIBWl6PO-z8kq3Eq2YEI3n2-ZtiHOsbdoXQiIQ895vUroDrljoe1ikxdfQ/s1600/DSCF5876.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig6NmUq14HrQDlSlwCk2Edu2sWMnSAiCUOlUZYIQhPyHhavo9d8ElXzf_KGe3DDysao2HuR_3W7W3goKkNzOIBWl6PO-z8kq3Eq2YEI3n2-ZtiHOsbdoXQiIQ895vUroDrljoe1ikxdfQ/s640/DSCF5876.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkv7xfNN9IkTLh-lHJB3YEuQWxTk64Qb6zpuw1_lS2kJXgW_4FPzWECjnJJuQpmp_51l0XkjTL4-d05hKlsc40t3aTcQXlU_h-Ja74zZr6CLIC5MgtRSXgW7VLBdMDlGgTVPXM7aL8z9g/s1600/DSCF5877.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkv7xfNN9IkTLh-lHJB3YEuQWxTk64Qb6zpuw1_lS2kJXgW_4FPzWECjnJJuQpmp_51l0XkjTL4-d05hKlsc40t3aTcQXlU_h-Ja74zZr6CLIC5MgtRSXgW7VLBdMDlGgTVPXM7aL8z9g/s640/DSCF5877.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjE2T_OLdepdrhR8z-EZhYwveSFOyUpkivUfwfajilgEtV9mXCriwuVEYQgboioTsGXuhVydz5jaogtls6iQkUX6lHmx8ChQiT9pDcpvz80UuljiD32xuk-HHQ-i2_Vfxei_ARe506b0f8/s1600/DSCF5873.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjE2T_OLdepdrhR8z-EZhYwveSFOyUpkivUfwfajilgEtV9mXCriwuVEYQgboioTsGXuhVydz5jaogtls6iQkUX6lHmx8ChQiT9pDcpvz80UuljiD32xuk-HHQ-i2_Vfxei_ARe506b0f8/s640/DSCF5873.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlCNKT415nkhRCHCjC6F-nH7wc8Ar4_jBP2c5UbqESqpsnpdcW6tLEVjvxKvzYxNj8CHjXEiPt2isjS4jHidNmbQzFiRQMij7cA2W9rbN_imI1aDCnmuUiSjLOftfKNoZL5vqO-oo25R0/s1600/DSCF5874.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlCNKT415nkhRCHCjC6F-nH7wc8Ar4_jBP2c5UbqESqpsnpdcW6tLEVjvxKvzYxNj8CHjXEiPt2isjS4jHidNmbQzFiRQMij7cA2W9rbN_imI1aDCnmuUiSjLOftfKNoZL5vqO-oo25R0/s640/DSCF5874.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr8Nhq745h2gPznOceb1GI2Cdh2o0upQ6HHBAspgGQXacQN0ZRYYnFemyHmVzQu7SPiyS7phsFQXCnu5D1b1sHtIQQRA3qDHhb-L830nEWCmfLa-GmEEaTMI9GkGzVh12EkBhBuV2GMZo/s1600/DJI_0023.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr8Nhq745h2gPznOceb1GI2Cdh2o0upQ6HHBAspgGQXacQN0ZRYYnFemyHmVzQu7SPiyS7phsFQXCnu5D1b1sHtIQQRA3qDHhb-L830nEWCmfLa-GmEEaTMI9GkGzVh12EkBhBuV2GMZo/s640/DJI_0023.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsQy_51HkuoIf8ESdRbkUaXmVcPnxlolYW8BdDsoto5kYp8C8VuqdvSNR26s7mF44wAo0_dNvl-KcaxoudU7-UJ4h7us84clTK47rDI014beJGXgNMkEao7VH_wnhLjDfbfXsftdRr9bw/s1600/DJI_0027.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsQy_51HkuoIf8ESdRbkUaXmVcPnxlolYW8BdDsoto5kYp8C8VuqdvSNR26s7mF44wAo0_dNvl-KcaxoudU7-UJ4h7us84clTK47rDI014beJGXgNMkEao7VH_wnhLjDfbfXsftdRr9bw/s640/DJI_0027.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9cEmWwzwW6etO500m1sL9K4FYPYzRdV0ZSiJ1d0x9ty9GYBkjc5wCQssknL4X9r8n0ysCRQVJ-nQcGA-TNDV7ppZPHDilST_H6Oz8aOhfDhxkYlP9mXOyuWUK8aXwmgSksS3B6RZxB3s/s1600/DSCF5912.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="424" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9cEmWwzwW6etO500m1sL9K4FYPYzRdV0ZSiJ1d0x9ty9GYBkjc5wCQssknL4X9r8n0ysCRQVJ-nQcGA-TNDV7ppZPHDilST_H6Oz8aOhfDhxkYlP9mXOyuWUK8aXwmgSksS3B6RZxB3s/s640/DSCF5912.JPG" width="640" /></a></div>
<br />you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-24233213062581711142016-02-28T16:17:00.000+09:002016-02-28T16:17:32.950+09:00Remote Shutter for ThetaS v1.0を公開しました<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://geo.itunes.apple.com/jp/app/remote-shutter-for-thetas/id1084103414?mt=8" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img alt="" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJuGOp9nbmezUo8JwHQSCyfOdamXJmeITRhyphenhyphenMIWhKBSiEhX8jDo_J8dqvjqGBIrduVoee0GFgzYIQl2Iwg6coh37BDrPJMW6fQpBRQogfgeYyQvTPjBq9nmNuaMN_IVILck3CQA2YGsa0/s1600/Icon-24%25402x.png" title="" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="line-height: 1.875;">久しぶりにアプリをリリースしました。</span><br />
<span style="line-height: 1.875;">自作アプリをはじめて作成したのが、約5年前ですが、初の有料アプリです。</span><br />
今回はAppleWatchに応しています。というかそっちメインです。<br />
拍手したら、ThetaS(カメラ)のシャッターが切れます。以前ブログを書いて意外にも反響があったのでアプリとして出してみました。<a href="https://yuichi-dev.blogspot.jp/2015/12/AppleWatch-ThetaS-RemoteControl.html" style="box-sizing: border-box; color: #23527c; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; outline: 0px; word-break: break-all; word-wrap: break-word;">AppleWatchからTheta Sを操作して遊んでみた</a><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg39DX5BjENQSrm8cx3ureDwUxhBtn9sxqKyUwoLQQm6vcKrOoHWxs_UvlxBgabu7xaRjRPTpKlevHZZC_KSdXrv2YQgAwcymBIuELcwA9CQ44c_cvZdKFQhSz0I1xlH-AZEFvl_2QtVI/s1600/remoteShutter.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg39DX5BjENQSrm8cx3ureDwUxhBtn9sxqKyUwoLQQm6vcKrOoHWxs_UvlxBgabu7xaRjRPTpKlevHZZC_KSdXrv2YQgAwcymBIuELcwA9CQ44c_cvZdKFQhSz0I1xlH-AZEFvl_2QtVI/s640/remoteShutter.gif" width="640" /></a></div>
<br /></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="app-storeの紹介文は以下" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/ecc50a8ce91d84a5f6dc#app-store%E3%81%AE%E7%B4%B9%E4%BB%8B%E6%96%87%E3%81%AF%E4%BB%A5%E4%B8%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>App Storeの紹介文は以下</h2>
<blockquote style="background-color: white; border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 4px; box-sizing: border-box; color: #555555; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 22.8571px; margin: 1em 0px 1em 0.8em; padding: 0.8em;">
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
【ThetaS(RICOH)】Theta sが必要です。<br />
カメラ(ThetaS)は、Wi-Fiネットワークを介してスマートフォンに接続されている場合、リモートで写真、ビデオ撮影することが可能です。<br />
iOS appまたはAppleWatchから使用することができます。</div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
**************<span style="box-sizing: border-box; font-weight: 900;"><em style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', 游ゴシック, YuGothic, sans-serif;">機能</em></span>***************</div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
・リモートシャッター<br />
・リモート動画撮影<br />
・撮影音コントロール(無音or 100)<br />
・手を叩いて、静止画の撮影(Apple Watchオンリー)</div>
</blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9A6FH4BmygfeZu3xTnR2PxxYe_vkSE-hurcbJfneLUOsNVM1Vs1Z0l7oxviz3CPDLVAzPyszs5a4iHYxVyQcc11DTFbm97y3RpAmMEoA24q9Sq2bpihNmcQ63S-91uxAFzt_rwMIdIeU/s1600/IMG_8726.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9A6FH4BmygfeZu3xTnR2PxxYe_vkSE-hurcbJfneLUOsNVM1Vs1Z0l7oxviz3CPDLVAzPyszs5a4iHYxVyQcc11DTFbm97y3RpAmMEoA24q9Sq2bpihNmcQ63S-91uxAFzt_rwMIdIeU/s400/IMG_8726.PNG" width="223" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhniG5XJ7AGQu7nkdJ985wMxe7Ys8FQjLOqpogdr92OZcVNejzqSunST_t65fa9grnE3lE6eRic9_thdtoh7L3rHNGZkF6M4yAmDJGJOboifsS2dIlDBD4mw8OrGD1KCObe_bKf-rnRtyI/s1600/IMG_8725.PNG" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhniG5XJ7AGQu7nkdJ985wMxe7Ys8FQjLOqpogdr92OZcVNejzqSunST_t65fa9grnE3lE6eRic9_thdtoh7L3rHNGZkF6M4yAmDJGJOboifsS2dIlDBD4mw8OrGD1KCObe_bKf-rnRtyI/s200/IMG_8725.PNG" width="160" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfxRZg70EbnpzBg4fmiJktvwW0EfvLtJX4U2Cf01o_fzDsy1pTfn20Ye3zism3_NcYI2w5VUeuCYfttFJqH1nUe-oT73cfpiS4hwFt-_nlPP9dnhMUENt9RXkijnuCYeeHGKyJnw08cMM/s1600/IMG_8723.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img alt="" border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfxRZg70EbnpzBg4fmiJktvwW0EfvLtJX4U2Cf01o_fzDsy1pTfn20Ye3zism3_NcYI2w5VUeuCYfttFJqH1nUe-oT73cfpiS4hwFt-_nlPP9dnhMUENt9RXkijnuCYeeHGKyJnw08cMM/s200/IMG_8723.PNG" title="" width="160" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghBWOmY-xR9RfYQFqMXVRCoqe_f_16AjpTVqPAhs9vLgXAlpc1Jo-0tMkJSYe1x-Rj0hA9xTyc_vkQ5dX1w2KsybmGNYs3KrzWKlLHVFtRirt1InI6zVLjUyA2_2mYt_58Adx28G0KK9g/s1600/IMG_8724.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghBWOmY-xR9RfYQFqMXVRCoqe_f_16AjpTVqPAhs9vLgXAlpc1Jo-0tMkJSYe1x-Rj0hA9xTyc_vkQ5dX1w2KsybmGNYs3KrzWKlLHVFtRirt1InI6zVLjUyA2_2mYt_58Adx28G0KK9g/s200/IMG_8724.PNG" width="160" /></a> </div>
<br />
<br />
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<span style="font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;">ThetaS(RICHO)の360度全天球の写真、動画をすぐ撮影するためのアプリケーションです。</span><span style="font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;">AppleWatchからだと、拍手(手をたたく)だけでシャッターが切れます。</span><br />
<span style="font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;">公式のアプリではAppleWatchに対応していないので、watchアプリ出してほしいとの声がありました。</span><span style="font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;">AppleWatchなら時計なので、そのまま腕を押すだけで、シャッターが押せる。アプリからより楽。それにwatchからの方がリモート感が増します!歩きながら、走りながらとか撮影可能です。</span><br />
<br /></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="ダウンロードはこちら" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/ecc50a8ce91d84a5f6dc#%E3%83%80%E3%82%A6%E3%83%B3%E3%83%AD%E3%83%BC%E3%83%89%E3%81%AF%E3%81%93%E3%81%A1%E3%82%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>ダウンロードはこちら</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
ダウンロードはこちらからどうぞ。120円です。</div>
<a href="https://geo.itunes.apple.com/jp/app/remote-shutter-for-thetas/id1084103414?mt=8" style="background: url("http://linkmaker.itunes.apple.com/images/badges/en-us/badge_appstore-lrg.svg") no-repeat; display: inline-block; height: 40px; overflow: hidden; width: 165px;"></a>
<br />
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<br /></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://geo.itunes.apple.com/jp/app/remote-shutter-for-thetas/id1084103414?mt=8" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
ThetaS とAppleWatchユーザの方はぜひお使いくださいませ。</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-11712988416849797422016-01-21T07:48:00.001+09:002016-01-21T07:51:22.013+09:00プロクラウドワーカーに認定されました<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
表題通り。<br />
クラウドソーシング大手「クラウドワークス」のプロクラウドワーカーに選ばれていました。<br />
<a class="autolink" href="https://crowdworks.jp/lp/procrowdworker?ref=blog1206" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://crowdworks.jp/lp/procrowdworker?ref=blog1206</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/c41d8274-f316-1d3e-3380-852de97ce252.jpeg" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="og.jpg" src="https://qiita-image-store.s3.amazonaws.com/0/8972/c41d8274-f316-1d3e-3380-852de97ce252.jpeg" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
クラウドワークスでのプロフィールはこちら<br />
<a class="autolink" href="https://crowdworks.jp/public/employees/277964" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://crowdworks.jp/public/employees/277964</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="どういう基準" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/8c937718dc67d95837a8#%E3%81%A9%E3%81%86%E3%81%84%E3%81%86%E5%9F%BA%E6%BA%96" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>どういう基準?</h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">実行力がある(納品完了率90%)</li>
<li style="box-sizing: border-box;">顧客満足度が高い(クライアント評価4.8以上)</li>
<li style="box-sizing: border-box;">収益力がある(獲得報酬額上位20%以内)</li>
<li style="box-sizing: border-box;">指名数が多い(スカウト数10回以上)</li>
<li style="box-sizing: border-box;">信用力が高い(本人確認済み)</li>
</ul>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
上記の基準を満たしたということで、プロフィールにプロクラウドワーカーマークが表示されていました。<br />
今回認定されたエンジニア、デザイナーのプロクラウドワーカーの総数は1540名なので、数として多いのか少ないのか、どうなんでしょうか。ワーカー自体の総数はエンジニア、デザイナーだけで数万人はいると思うので、満足していいのかな...<br />
上位ランクイン実績(月間ランキング)2015年2月に6位になったことがハイライトで、クラウドワークスがメインの収益ではなくなったのですが意外でした。<br />
<a class="autolink" href="https://crowdworks.jp/public/employees/277964/ranking" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://crowdworks.jp/public/employees/277964/ranking</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="一年間やってきて" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/8c937718dc67d95837a8#%E4%B8%80%E5%B9%B4%E9%96%93%E3%82%84%E3%81%A3%E3%81%A6%E3%81%8D%E3%81%A6" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>一年間やってきて</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
期間中お取引をいただきましたお客様はもちろんのこと、これまで関わっていただきました多くの方々に感謝いたします!</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
いつでも、どこでも仕事ができるフリーランスという生き方、やりたいこと、得意なことで生きていけるということは幸せな限りです。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="今後について" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/8c937718dc67d95837a8#%E4%BB%8A%E5%BE%8C%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>今後について</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
これからもクラウドソーシング業界の発展に貢献すると同時に、新しい働き方の実現と新たな価値の創造、好奇心赴くおもしろいと思うことに挑戦していきたいなと思っています。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
ちなみに最近,クラウドワークスで受注した仕事は、<br />
センサー付きメガネJ!NS MEME(ミーム)向けiOSアプリ、Webアプリ(データ格納、PC上に画面表示、CSV出力)の開発です。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
JinsMEMEを購入した甲斐がありました\(^o^)/</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
引き続き、よろしくお願いいたします!</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-59558781190122224942016-01-10T11:34:00.001+09:002016-01-10T11:34:08.911+09:00新年早々、PayPalアカウントをハッキングされた話<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
新年早々、ベッキーの不倫騒動が世間を賑わせてますが、そんなことはさておき、<br />
<br /></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="残高がすっからかん" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/c6bc5e86de1f23141f06#%E6%AE%8B%E9%AB%98%E3%81%8C%E3%81%99%E3%81%A3%E3%81%8B%E3%82%89%E3%81%8B%E3%82%93" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>残高がすっからかん</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/9f91ddf1-ea99-ad3f-3f51-c7935e794bfc.jpeg" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="6306561065_01b09bc127_b.jpg" src="https://qiita-image-store.s3.amazonaws.com/0/8972/9f91ddf1-ea99-ad3f-3f51-c7935e794bfc.jpeg" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
久々に買い物をpaypal決済でしようと思い、<br />
ログインしてみて、残高を確認すると見覚えのない引き出しが多数、ログインしていない数ヶ月間の間に<span style="line-height: 1.875;">すっからかんになっていた\(^o^)/</span></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
支払いをPaypalで受けることもあったので、引き出していないお金をずっとプールしていたのですが、久しぶりに確認してみるとこの有様!<br />
ログインしてみると覚えのないメールアドレス、銀行口座、クレジットカードが登録されていて、取引履歴を確認すると、どこかの口座にどんどん振り込まれている履歴が残っていた!</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
え?これ返金してもらえないの?どうしよ…<br />
あくせく働いたお金がぱーなのか...<br />
と思ってググったら同じような被害の記事を発見。<br />
まぁ戻ってくるのかなとひと安心、、、</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="速攻paypalに電話" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/c6bc5e86de1f23141f06#%E9%80%9F%E6%94%BBpaypal%E3%81%AB%E9%9B%BB%E8%A9%B1" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>速攻paypalに電話</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
ネイティブではない日本語でおそらく東南アジア系のお姉さんの声...<br />
状況を説明すると、冷静に聞いてくれる...<br />
一時的にアカウントを凍結して、不正な取引に関しては全額返金してくれるとのこと。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
三年前くらいは日本語対応すらなかったのに対応が素晴らしい、、、</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="ひと安心" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/c6bc5e86de1f23141f06#%E3%81%B2%E3%81%A8%E5%AE%89%E5%BF%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>ひと安心</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
三時間くらい経過して再び電話。<br />
取引履歴を確認すると、残額が元通りに( ´・‿・`)</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
パスワードの変更をしたり(定期的なパスワードの変更は必要と実感)、<br />
メールアドレスの変更をしたり、<br />
もろもろの処理をして、一安心</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="問い合わせ対応がとても親切安心" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/c6bc5e86de1f23141f06#%E5%95%8F%E3%81%84%E5%90%88%E3%82%8F%E3%81%9B%E5%AF%BE%E5%BF%9C%E3%81%8C%E3%81%A8%E3%81%A6%E3%82%82%E8%A6%AA%E5%88%87%E5%AE%89%E5%BF%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>問い合わせ対応がとても親切、安心</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/c4756602-9e7f-1dfd-89dd-7b5e42d606d0.jpeg" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="shutterstock_86935414.jpg" src="https://qiita-image-store.s3.amazonaws.com/0/8972/c4756602-9e7f-1dfd-89dd-7b5e42d606d0.jpeg" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
何度か電話をかけたり、受けたりしてたんですが、皆総じて、丁寧な敬語で対応がスピーディで安心しました、そして皆ネイティヴではない日本語で東南アジア風のかた。日本人ではない人が丁寧な敬語を使うと印象がすごくいい気がした。コールセンターは海外にあるんでしょうね。さすがグローバル企業。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
原因は不明ですが、おそらくパスワードの漏洩でハッキングされたので、今後一切paypalを利用しない方がいいだろうなと心決めてたのですが、お姉さんの綺麗な言葉遣い、冷静でスピーディーな対応に感服しました。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
生体認証、静脈認証がデフォルトになれば、漏洩やパスワード入力の煩雑さから解放されるんですが、そんな世界はもう少し先でしょう。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="最後に" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/c6bc5e86de1f23141f06#%E6%9C%80%E5%BE%8C%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>最後に</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
お金もちゃんと返ってきたし、気持ちのいい対応をしてもらったので、今後もpaypalを利用させてもらおうと思いました。<br />
コールセンターをソフトバンクのようにほぼすべて自動音声にしてしまうのもありだと思いますが、今回の件で、人だからこそできるサービスというのを実感しましたね。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
担当のジェニー(ケニー?)さん、ありがとうございました。美声でした。</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-57149569612612891062015-12-31T18:17:00.000+09:002016-09-08T04:41:36.996+09:002015年振り返り〜フリーランスになって約一年<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
2015年を振り返ります。すぐ忘れるので備忘録として。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
今年は個人事業主(フリーランス)になってはじめての年だったので、経験的な意味でも様々なことが起こった年でした。<br />
<br /></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/bbbbe5af-a14d-9d95-de28-6e2a91064674.jpeg" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="11917878_654779647995836_891629246_n.jpg" src="https://qiita-image-store.s3.amazonaws.com/0/8972/bbbbe5af-a14d-9d95-de28-6e2a91064674.jpeg" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="11917878_654779647995836_891629246_n.jpg" /></a><br />
(<a href="https://www.instagram.com/p/7mSYUaTKfZ/?taken-by=you_matz" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank">@襟裳岬より 9月</a>)</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="2月に個人事業主として登記" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#2%E6%9C%88%E3%81%AB%E5%80%8B%E4%BA%BA%E4%BA%8B%E6%A5%AD%E4%B8%BB%E3%81%A8%E3%81%97%E3%81%A6%E7%99%BB%E8%A8%98" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>2月に個人事業主として登記</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
2014年9月に前職を離れて、そこからは転職を考えていて、東京の会社から内定をもらったりしていました。内定先は報酬の面では満足していましたが、気持ち的に引っかかる部分があって、リモートワークを東京〜京都間ではじめはして、これならフリーランスでいけるんじゃないかということではじめました。はじめは友達に仕事をもらったり、知り合いを紹介してもらったりして細々とやっていました。<br />
<br />
私のプロフィールサイトは<a href="http://manchan.github.io/" target="_blank">こちら</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="やってきたこと" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#%E3%82%84%E3%81%A3%E3%81%A6%E3%81%8D%E3%81%9F%E3%81%93%E3%81%A8" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>やってきたこと</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
まずは受託でいろんな仕事をやってきました。<br />
内訳としては、Web上、リアル半々という形です。<br />
クラウドワークスでの評価としては、受注実績21件、評価5.0<br />
最高の月間契約ランキングは6位でした。<br />
<a href="https://crowdworks.jp/public/employees/277964/ranking" target="_blank">https://crowdworks.jp/public/employees/277964/ranking</a></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="フリーランスになって三ヶ月後の振り返り" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#%E3%83%95%E3%83%AA%E3%83%BC%E3%83%A9%E3%83%B3%E3%82%B9%E3%81%AB%E3%81%AA%E3%81%A3%E3%81%A6%E4%B8%89%E3%83%B6%E6%9C%88%E5%BE%8C%E3%81%AE%E6%8C%AF%E3%82%8A%E8%BF%94%E3%82%8A" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>フリーランスになって三ヶ月後の振り返り</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<a class="autolink" href="http://yuichi-dev.blogspot.jp/2015/05/blog-post.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://yuichi-dev.blogspot.jp/2015/05/blog-post.html</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
大阪の梅田に拠点を移して(今は京都)、はじめてリアルではないWeb上で仕事をもらって、本当に数十万円とか振り込んでくれるのかなみたいな不安がすごくありました。この三ヶ月はすごくナーバスだったのを覚えています。<br />
4月にAppleWatch発売前の実機検証のためApple日本法人(東京、六本木)にいったのですが、エンジニアの方と実際に話ができて、夢のような体験でした。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://itunes.apple.com/jp/app/campus-voice/id1005516011?mt=8" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">Campus Voice</a>という位置情報をベースにした匿名型twitter型、SNSアプリ(慶應、東大のキャンパス内のつぶやきも見れます)を新規開発(APIサーバもアプリもすべて担当)したのですが、 現在だいぶ過疎ってきてるので、誰か使ってください・ω・人が集まって交流してはじめておもしろくなるアプリなので。大学生じゃなくても、20KM圏内で近くの人と話せます。</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="フリーランスとして活動し始めて2015年2月半年" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#%E3%83%95%E3%83%AA%E3%83%BC%E3%83%A9%E3%83%B3%E3%82%B9%E3%81%A8%E3%81%97%E3%81%A6%E6%B4%BB%E5%8B%95%E3%81%97%E5%A7%8B%E3%82%81%E3%81%A62015%E5%B9%B42%E6%9C%88%E5%8D%8A%E5%B9%B4" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>フリーランスとして活動し始めて(2015年2月〜)、半年</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<a class="autolink" href="http://yuichi-dev.blogspot.jp/2015/08/20152.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://yuichi-dev.blogspot.jp/2015/08/20152.html</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
ありがたいことに半年が経過して、ある程度安心できるようになりました。<br />
9月からは仕事の量はおさえつつ、人に会いにいったり、旅行に行ったりして、文化的なものに触れて、視野を広げようとしていました。<br />
Osaka Github Meetupにいったり、起業家のイベントにいったり、勉強会にいったり、そこで出会った方と仕事につながったり、おもしろいねと言ってくれる方がいたり、自分はまだまだだなと反省したりしていました。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
来年ははじめて、勉強会を主催してみようと計画しています。<br />
<a href="https://memedevkyoto.doorkeeper.jp/events/36705" target="_blank">MemeDev Kyoto Vol.1</a></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="最近はなにをしているのか" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#%E6%9C%80%E8%BF%91%E3%81%AF%E3%81%AA%E3%81%AB%E3%82%92%E3%81%97%E3%81%A6%E3%81%84%E3%82%8B%E3%81%AE%E3%81%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>最近はなにをしているのか</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
開発案件は同時進行でCMS開発とiOSが走っていて、来年もすごく楽しみな案件が何個かあります。<br />
11月、12月は気になっていたデバイスを買いまくって、遊んでいました。仕事でお声がけいただいた会社を訪問して、Pepperで遊んだり、その他は以下です。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://www.instagram.com/p/-VuggdzKes/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"><b>人の顔を検知して動くラジコン</b></a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<b>JINS MEME × IoT</b><br />
<a class="autolink" href="http://yuichi-dev.blogspot.jp/search/label/JinsMeme" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://yuichi-dev.blogspot.jp/search/label/JinsMeme</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<b>AppleWatchからTheta Sを操作して遊んでみた</b><br />
<a class="autolink" href="http://yuichi-dev.blogspot.jp/2015/12/AppleWatch-ThetaS-RemoteControl.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://yuichi-dev.blogspot.jp/2015/12/AppleWatch-ThetaS-RemoteControl.html</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="買ったものとか" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#%E8%B2%B7%E3%81%A3%E3%81%9F%E3%82%82%E3%81%AE%E3%81%A8%E3%81%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>買ったものとか</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
今年はいろいろと買いました。自己投資という意味でも。<br />
<a href="http://www.amazon.co.jp/gp/product/B00FQ0YNOS/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=247&creative=1211&creativeASIN=B00FQ0YNOS&linkCode=as2&tag=manson0615-22" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">19インチ、スクエアディスプレイ</a>。スクリーンはヨコ型ワイドが主流ですが、<br />
縦型なので文章が読みやすいし、Xcodeでの作業も便利です。<br />
<a href="https://www.blogger.com/null" style="background-color: transparent; box-sizing: border-box; color: #337ab7; word-break: break-all; word-wrap: break-word;">Kindle Voyage(読書)</a>、<a href="http://www.apple.com/jp/watch/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">AppleWatch(時計)</a>、<a href="https://jins-meme.com/ja/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">JINS MEME(メガネ)</a>, <a href="http://www.amazon.co.jp/gp/product/B014US3FQI/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=247&creative=1211&creativeASIN=B014US3FQI&linkCode=as2&tag=manson0615-22" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">THETA S(カメラ)</a>, <a href="http://www.amazon.co.jp/gp/product/B00M1IFL3U/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=247&creative=1211&creativeASIN=B00M1IFL3U&linkCode=as2&tag=manson0615-22" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">Philips Hue(LEDライト)</a>,あとは服を買って、おいしいご飯を食べて、美術館もやたらと行ってました。</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="applewatch" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#applewatch" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>AppleWatch</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
みんなになにがいいの?って聞かれますが、Apple信者なので、お布施ですと答えています。\(^o^)/<br />
当初は仕事に必要なので買いましたが、通知用のデバイスとして優れていますし、身体情報の測定とか、ジムにいくので、もろもろわかっていいんです!1日の活動カロリーのゴールを設定して、達成できるとふいに突然教えてくれるので、おもしろいです。非言語的、非視覚的表現の可能性があるんです。<br />
<br /></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/bb6ce00f-539f-a78a-8e53-63f159615bc3.jpeg" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="AppleWatch.jpg" src="https://qiita-image-store.s3.amazonaws.com/0/8972/bb6ce00f-539f-a78a-8e53-63f159615bc3.jpeg" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="theta-s" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#theta-s" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>THETA S</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
カメラの最終形態。もう文句なしです。GoProを使わなくなってしまうくらい楽しいです。どこいくにも連れて行きます。GoProだれか買ってくれへんかな...</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
下の写真をぐりぐりしてみてくださいね。</div>
<blockquote class="ricoh-theta-spherical-image" data-height="485" data-width="900">
京都市内一望 #theta360 - <a href="https://theta360.com/s/hRkoZjFoeTMVnyj8j8goCrjd6" target="_blank">Spherical Image - RICOH THETA</a></blockquote>
<script async="" charset="utf-8" src="https://theta360.com/widgets.js"></script>
<br />
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="philips-hue" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#philips-hue" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>Philips Hue</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
API操作できる1600万色の表現力を持つLEDライトです。いろいろと調光できておもしろいです。<br />
下の写真はまばたきでライトをランダムに変更するというのを撮影した写真です。<br />
PVみたいに撮影してもらって感動しました!( ´・‿・`)<br />
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/4df2ca95-669a-bed8-3364-0377eea2e201.png" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="matsu.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/4df2ca95-669a-bed8-3364-0377eea2e201.png" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="matsu.png" /></a></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="個人事業主になってみて" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#%E5%80%8B%E4%BA%BA%E4%BA%8B%E6%A5%AD%E4%B8%BB%E3%81%AB%E3%81%AA%E3%81%A3%E3%81%A6%E3%81%BF%E3%81%A6" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>個人事業主になってみて</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
結果的に現時点ではやりたいことができているので、すごくよかったなというのが実感としてあります。生活が安定しないんじゃない?とか言われますが、そこは払拭できそうかな〜なんて楽観的に考えています。死ぬまで安心できるというのはほとんどの人はないでしょうしね。<br />
雇われの身でも将来に対して漠然と不安に感じているのは同じなので( ´・‿・`)<br />
新しい仕事や経験がどんどんでき、かつ自由に動けて、今の状況に満足していますが、対外的な成果という意味ではまだまだです。来年はこの辺りどんどん狙っていきますよ。</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="2016年に向けてやること" style="box-sizing: border-box; display: block; font-weight: normal; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/969d412b8d0134caf4df#2016%E5%B9%B4%E3%81%AB%E5%90%91%E3%81%91%E3%81%A6%E3%82%84%E3%82%8B%E3%81%93%E3%81%A8" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>2016年に向けて、やること</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
・やっていることを公表して、それを続けること。<br />
・システム化してどうしたら売れるかまで考える<br />
・プロトタイプ作って満足しがちなのでブラッシュアップしていくこと。<br />
・起業家、優秀な人から吸収していくこと<br />
・法人化に向けて事業化とはなにか考え、本を読む<br />
・来年はWWDCに行く<br />
・仕事がらみで海外に行く<br />
・Amazon IoTとAmazonMachineLearningでなんかやりたい<br />
・クライアントワークばっかりなので個人でアプリ出す<br />
・<a href="http://www.tryswiftconf.com/" target="_blank">try! Swift</a>が楽しみ!<br />
・趣味としてゴルフをはじめる</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<br />
<br /></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
他にもやりたいことが多すぎるので、すべてやっちゃえと思いますが、この辺、取捨選択に困っています。死なずにいかにいろいろな経験をできるかというテーマがあるので。<br />
大成したいなら、この辺とどう折り合いをつけるか。<br />
アイディアだけは山程あります。お金になるかどうかは分かりません\(^o^)/<br />
本当に必要になったタイミングで集中してエンジンかけてキャッチアップしていければOKな気はしています。<br />
<br />
というわけで2016年もよろしくお願いします。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
ではまた</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-32683844875720786852015-12-22T07:00:00.000+09:002016-02-28T10:04:58.523+09:00AppleWatchからTheta Sを操作して遊んでみた<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
この記事は<a href="http://qiita.com/advent-calendar/2015/theta" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">RICOH THETA Advent Calendar 2015</a>の22日目の記事です。<br />
<br /></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDsmg42HdImLdi2A_TLAzXHZTnu025hzVn1Z7US5f-7C3XOusdOSUXEqMWWknMgbqgY37C0o8QqLgU1EtPto3qLtswUDXEL4iz19efoprYJd9rnqMq8HtrTmrlQOa5-kuI5A3lhLre5aw/s1600/IMG_7996.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDsmg42HdImLdi2A_TLAzXHZTnu025hzVn1Z7US5f-7C3XOusdOSUXEqMWWknMgbqgY37C0o8QqLgU1EtPto3qLtswUDXEL4iz19efoprYJd9rnqMq8HtrTmrlQOa5-kuI5A3lhLre5aw/s640/IMG_7996.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #4a4a4a; font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif; font-size: 16px; line-height: 30px;">今回はAppleWatchからTHETA Sのリモートコントロール(静止画、動画撮影)を実装したので公開したいと思います。</span><span style="background-color: white; color: #4a4a4a; font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif; font-size: 16px; line-height: 30px;">もちろん無音シャッターもありです。※用法、音量にはご注意を!</span></div>
<span style="background-color: white; color: #4a4a4a; font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif; font-size: 16px; line-height: 30px;">THETA SなのでAPIはv2です。</span><br />
<div class="separator" style="clear: both; text-align: left;">
<span style="background-color: white; color: #4a4a4a; font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif; font-size: 16px; line-height: 30px;">そもそもAppleWatchユーザでかつThetaSの方ってどのくらいいるのでしょうか。</span></div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
※2016.2.7追記</h2>
<div class="separator" style="clear: both;">
<span style="background-color: white; color: #4a4a4a; font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif; font-size: 16px; line-height: 30px;"></span></div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
この記事をベースにアプリを公開しました。詳細は以下<br />
<a href="http://yuichi-dev.blogspot.jp/2016/02/remote-shutter-for-thetas-v1.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">Remote Shutter for ThetaS v1.0を公開しました</a></div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
<br /></div>
</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="theta-sとは" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#theta-s%E3%81%A8%E3%81%AF" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>THETA Sとは</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
もはや説明不要かと思いますが、<br />
全天球の360度の写真、動画が取れるカメラデバイスです。<br />
詳しくはRICOH THETA Advent Calendarの一日目の記事を参考にしてください。<br />
<a class="autolink" href="http://panora.tokyo/3945/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://panora.tokyo/3945/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
2015/12/22日現在、コンパクトデジタルカメラの<a href="http://www.amazon.co.jp/gp/product/B014US3FQI/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=247&creative=1211&creativeASIN=B014US3FQI&linkCode=as2&tag=manson0615-22" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">ベストセラー一位</a>となっています。すごい!<br />
どんな写真をとっても360度で撮れるので、すごくおもしろいです。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
写真を見たほうがわかりやすいので、京都の紅葉の写真と市内一望の写真をあげていますのでこちらを見てグリグリ触って確認してみてください。下の写真にフォーカスを当てて、キーボードの上下左右を押しても360度、見ることができますよ!</div>
<blockquote class="ricoh-theta-spherical-image" data-height="485" data-width="900">
京都は今年最後の紅葉風景です。 また来年。 #theta360 - <a href="https://theta360.com/s/ggfzOctuek5ARYlqD8XjEEev6" target="_blank">Spherical Image - RICOH THETA</a></blockquote>
<script async="" charset="utf-8" src="https://theta360.com/widgets.js"></script>
<br />
<blockquote class="ricoh-theta-spherical-image" data-height="485" data-width="900">
京都市内一望 #theta360 - <a href="https://theta360.com/s/hRkoZjFoeTMVnyj8j8goCrjd6" target="_blank">Spherical Image - RICOH THETA</a></blockquote>
<script async="" charset="utf-8" src="https://theta360.com/widgets.js"></script>
<br />
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<span style="line-height: 1.875;">写真をグリグリ触る体験て新しい!</span><br />
<span style="line-height: 1.875;"><br /></span></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="なんでapplewatchから" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#%E3%81%AA%E3%82%93%E3%81%A7applewatch%E3%81%8B%E3%82%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>なんでAppleWatchから?</h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">THETA Sはボタンを押したらすぐ写真がとれるのですが、どうしても指が写ってしまう。</li>
<li style="box-sizing: border-box;">上記の紅葉の写真みたいにスマホアプリからシャッター押せますがどうしてもうつむきがちになって顔が映らない</li>
<li style="box-sizing: border-box;">AppleWatchなら時計なので、そのまま腕を押すだけで、シャッターが押せる。アプリからより楽。それにwatchからの方がリモート感が増します!</li>
<li style="box-sizing: border-box;">歩きながら、走りながらとか撮影可能(ウェラブルデバイスゆえに!)</li>
</ul>
<div>
<br /></div>
<div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
AppleWatch単体でTHETA SとWifi接続できるの?</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
できます。<br />
AppleWatchはiPhoneのペアリングして動作し、ネットワークに関してもiPhone経由でのアクセスでした。watchOS2からは単体でもWifiのネットワークに接続すること(iPhone側で接続したことがある既知のネットワーク)が可能です。</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="iphoneが近くあってbluetoothオンの場合" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/74f124c6189addc70ed9#iphone%E3%81%8C%E8%BF%91%E3%81%8F%E3%81%82%E3%81%A3%E3%81%A6bluetooth%E3%82%AA%E3%83%B3%E3%81%AE%E5%A0%B4%E5%90%88" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>iPhoneが近くあって、Bluetoothオンの場合</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
消費電力を節約するため、iPhone経由で接続<br />
グランス設定画面で <span style="box-sizing: border-box; font-weight: 900;">接続済み</span> の表示<br />
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/42184aed-b400-5148-9011-3d02b1289f38.png" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="IMG_8028.PNG" src="https://qiita-image-store.s3.amazonaws.com/0/8972/42184aed-b400-5148-9011-3d02b1289f38.png" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="bluetoothオフでiphoneとの接続が切れている場合" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/74f124c6189addc70ed9#bluetooth%E3%82%AA%E3%83%95%E3%81%A7iphone%E3%81%A8%E3%81%AE%E6%8E%A5%E7%B6%9A%E3%81%8C%E5%88%87%E3%82%8C%E3%81%A6%E3%81%84%E3%82%8B%E5%A0%B4%E5%90%88" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>BluetoothオフでiPhoneとの接続が切れている場合</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
単体でAppleWatchはWi-Fiを使います。たとえば、<a href="https://support.apple.com/ja-jp/HT204562#wifi" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">互換性のあるWi-Fi</a>を利用できる環境下では、iPhoneがBluetoothの通信範囲内にない場合、AppleWatchはWi-Fiを使います。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
iPhoneがAppleWatchと接続された状態で、以前にwifi接続された既知のネットワークに接続した場合<br />
グランス設定画面で <span style="box-sizing: border-box; font-weight: 900;">緑の雲のアイコン</span> の表示<br />
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/a55d0457-541b-66f0-7cfe-4fdc1f238f13.png" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="IMG_8026.PNG" src="https://qiita-image-store.s3.amazonaws.com/0/8972/a55d0457-541b-66f0-7cfe-4fdc1f238f13.png" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
詳細についてはこちらを<br />
<a href="https://support.apple.com/ja-jp/HT204562" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">Apple Watch の Bluetooth と Wi-Fi について</a></div>
</div>
<div>
<br /></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="必要なもの環境" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#%E5%BF%85%E8%A6%81%E3%81%AA%E3%82%82%E3%81%AE%E7%92%B0%E5%A2%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>必要なもの、環境</h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">THETA S <a class="autolink" href="https://theta360.com/ja/about/theta/s.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://theta360.com/ja/about/theta/s.html</a></li>
<li style="box-sizing: border-box;">iOS 9.0+</li>
<li style="box-sizing: border-box;">AppleWatch WatchOS2</li>
<li style="box-sizing: border-box;">Xcode 7</li>
</ul>
<div>
<br /></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="実装" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#%E5%AE%9F%E8%A3%85" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>実装 </h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/1f88d6ad-eabf-e3b5-febf-82c96dd6d772.png" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="IMG_7984 (2).PNG" src="https://qiita-image-store.s3.amazonaws.com/0/8972/1f88d6ad-eabf-e3b5-febf-82c96dd6d772.png" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="IMG_7984 (2).PNG" /></a><br />
ラベルテキスト、ボタン二種を用意(ひとつは撮影用、ひとつは音声あり、なし制御)</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="getting-started" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#getting-started" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>Getting Started</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
まずはSDKを確認。<br />
<a class="autolink" href="https://developers.theta360.com/ja/docs/v2/api_reference/getting_started.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://developers.theta360.com/ja/docs/v2/api_reference/getting_started.html</a><br />
THETA SはHTTP接続でやり取りが可能。比較的容易。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
THETA Sのシャッターを押すために、HTTPネットワークライブラリと<br />
レスポンスがJSONなので、その処理用ライブラリ</div>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 1em; padding-left: 1.5em;">
<li style="box-sizing: border-box;">Alamofire</li>
<li style="box-sizing: border-box;">SwiftyJSON</li>
</ul>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
を利用します。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
Podfileにプロジェクト名は<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">ThetaDemo</code><br />
Watchkit Extensionとのリンクを記述<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">shared_pods</code>という名前で共通処理を定義<br />
iOSとwatch extension両方に<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">shared_pods</code>を記述<br />
そしてwatch extensionに<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">platform :watchos, '2.0'</code><br />
これを記述しないと実機ビルドができなかった。</div>
<div class="code-frame" data-lang="Podfile" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;">link_with "ThetaDemo", "ThetaWatch Watchkit Extension"
def shared_pods
use_frameworks!
pod 'Alamofire', '~> 2.0'
pod 'SwiftyJSON'
end
target 'ThetaDemo' do
shared_pods
end
target 'ThetaDemoTests' do
end
target 'ThetaDemoUITests' do
end
target 'ThetaWatch Extension' do
platform :watchos, '2.0'
shared_pods
end
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="theta-sとのセッションの開始" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#theta-s%E3%81%A8%E3%81%AE%E3%82%BB%E3%83%83%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E9%96%8B%E5%A7%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>THETA Sとのセッションの開始</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
デバイスとのセッションを開始し、sessionIdを取得します。<br />
セッションを切らさないようにタイマー処理で1秒ごとにセッションを更新しています。<br />
セッションの有効期間はデフォルトで180秒なので1秒じゃなくてもいいと思います。<br />
<a class="autolink" href="https://developers.theta360.com/ja/docs/v2/api_reference/commands/camera.update_session.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://developers.theta360.com/ja/docs/v2/api_reference/commands/camera.update_session.html</a></div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">InterfaceController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"><span class="k" style="box-sizing: border-box; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">WatchKit</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">Foundation</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">Alamofire</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">SwiftyJSON</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">class</span> <span class="nl" style="box-sizing: border-box;">InterfaceController</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">WKInterfaceController</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="p" style="box-sizing: border-box;">@</span><span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">IBOutlet</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">cameraStateLb</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">WKInterfaceLabel</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="nl" style="box-sizing: border-box;">commandExecURL</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">String</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"http://192.168.1.1/osc/commands/execute"</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">ssid</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span>
<span class="kr" style="box-sizing: border-box; font-weight: bold;">override</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">awakeWithContext</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">context</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">AnyObject</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">cameraStateLb</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">setText</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Connecting..."</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">session_start</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 1秒ごとにタイマーでセッション更新</span>
<span class="bp" style="box-sizing: border-box; color: #999999;">NSTimer</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">scheduledTimerWithTimeInterval</span><span class="p" style="box-sizing: border-box;">(</span><span class="mf" style="box-sizing: border-box; color: #009999;">1.0</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">target</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">selector</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">Selector</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"updateSession"</span><span class="p" style="box-sizing: border-box;">),</span> <span class="nl" style="box-sizing: border-box;">userInfo</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">repeats</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// セッション更新</span>
<span class="n" style="box-sizing: border-box;">private</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">updateSession</span><span class="p" style="box-sizing: border-box;">(){</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="p" style="box-sizing: border-box;">(</span><span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">!=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera.updateSession"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="n" style="box-sizing: border-box;">Alamofire</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">request</span><span class="p" style="box-sizing: border-box;">(.</span><span class="n" style="box-sizing: border-box;">POST</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">commandExecURL</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">encoding</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">JSON</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">responseJSON</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">switch</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Success</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data_dic</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSDictionary</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">ssid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data_dic</span><span class="p" style="box-sizing: border-box;">[</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"results"</span><span class="p" style="box-sizing: border-box;">]</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">[</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="p" style="box-sizing: border-box;">]</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span> <span class="n" style="box-sizing: border-box;">String</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">shootBt</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">setEnabled</span><span class="p" style="box-sizing: border-box;">(</span><span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">volumeBt</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">setEnabled</span><span class="p" style="box-sizing: border-box;">(</span><span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">cameraStateLb</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">setText</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Connected"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">ssid</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">ud</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSUserDefaults</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">standardUserDefaults</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="n" style="box-sizing: border-box;">ud</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">setValue</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">ssid</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">forKey</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">ssid</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">ud</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">synchronize</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Failure</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">error</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Request failed with error: \(error)"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">else</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">session_start</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// セッション開始</span>
<span class="n" style="box-sizing: border-box;">private</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">session_start</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera.startSession"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="n" style="box-sizing: border-box;">Alamofire</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">request</span><span class="p" style="box-sizing: border-box;">(.</span><span class="n" style="box-sizing: border-box;">POST</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">commandExecURL</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">encoding</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">JSON</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">responseJSON</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">switch</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Success</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data_dic</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSDictionary</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">data_dic</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">ssid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data_dic</span><span class="p" style="box-sizing: border-box;">[</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"results"</span><span class="p" style="box-sizing: border-box;">]</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">[</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="p" style="box-sizing: border-box;">]</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span> <span class="n" style="box-sizing: border-box;">String</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">ssid</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Failure</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">error</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Request failed with error: \(error)"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="theta-sで静止画撮影" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#theta-s%E3%81%A7%E9%9D%99%E6%AD%A2%E7%94%BB%E6%92%AE%E5%BD%B1" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>THETA Sで静止画撮影</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
静止画撮影するためのメソッドです。<br />
セッション開始して、取得したsessionIdを利用します。<br />
takePictureActionで撮影に成功すると、takePicture Success!!とアラートを出します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">InterfaceController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 静止画撮影</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="nf" style="box-sizing: border-box; color: #990000; font-weight: bold;">takePicture</span><span class="p" style="box-sizing: border-box;">(){</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera.takePicture"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="n" style="box-sizing: border-box;">Alamofire</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">request</span><span class="p" style="box-sizing: border-box;">(.</span><span class="n" style="box-sizing: border-box;">POST</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">commandExecURL</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">encoding</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">JSON</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">responseJSON</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">switch</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Success</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data_dic</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSDictionary</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">data_dic</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">defaultAction</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">WKAlertAction</span><span class="p" style="box-sizing: border-box;">(</span>
<span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"OK"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nl" style="box-sizing: border-box;">style</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">WKAlertActionStyle</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Default</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="p" style="box-sizing: border-box;">()</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">-></span> <span class="n" style="box-sizing: border-box;">Void</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">actions</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span><span class="n" style="box-sizing: border-box;">defaultAction</span><span class="p" style="box-sizing: border-box;">]</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">presentAlertControllerWithTitle</span><span class="p" style="box-sizing: border-box;">(</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"撮影完了"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nl" style="box-sizing: border-box;">message</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">""</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nl" style="box-sizing: border-box;">preferredStyle</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">WKAlertControllerStyle</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Alert</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="nl" style="box-sizing: border-box;">actions</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">actions</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Failure</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">error</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Request failed with error: \(error)"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">@</span><span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">IBAction</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">takePictureAction</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">takePicture</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="シャッターを無音にしたい場合" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#%E3%82%B7%E3%83%A3%E3%83%83%E3%82%BF%E3%83%BC%E3%82%92%E7%84%A1%E9%9F%B3%E3%81%AB%E3%81%97%E3%81%9F%E3%81%84%E5%A0%B4%E5%90%88" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>シャッターを無音にしたい場合</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
※くれぐれもご使用にはご注意を</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
デフォルトで 「<span style="box-sizing: border-box; font-weight: 900;">キュ〜イン</span> 」とかわいらしい音が鳴りますが、今回は消しちゃいます。<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">pushVolumeButton</code>アクションで実行可能です。<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">_shutterVolume</code>を0にすることで、シャッター音なしも可能となります。<br />
デフォルトで音量は100になっています。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">InterfaceController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="nf" style="box-sizing: border-box; color: #990000; font-weight: bold;">setShutterVolume</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">volume</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">Int</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">_</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera.setOptions"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"options"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"_shutterVolume"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span><span class="n" style="box-sizing: border-box;">volume</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="n" style="box-sizing: border-box;">Alamofire</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">request</span><span class="p" style="box-sizing: border-box;">(.</span><span class="n" style="box-sizing: border-box;">POST</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">commandExecURL</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">encoding</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">JSON</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">responseJSON</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">switch</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Success</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data_dic</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSDictionary</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">data_dic</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Failure</span><span class="p" style="box-sizing: border-box;">(</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">error</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Request failed with error: \(error)"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">@</span><span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">IBAction</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">pushVolumeButton</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">volumeZero</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">volumeZero</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span>
<span class="n" style="box-sizing: border-box;">setShutterVolume</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #009999;">100</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">volumeBt</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">setBackgroundImageNamed</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"VolumeOn"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">else</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">volumeZero</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span>
<span class="n" style="box-sizing: border-box;">setShutterVolume</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #009999;">0</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">volumeBt</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">setBackgroundImageNamed</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"VolumeOff"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="ビルド実行" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#%E3%83%93%E3%83%AB%E3%83%89%E5%AE%9F%E8%A1%8C" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>ビルド実行</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
THETA Sの電源を入れ、iPhoneのWifi設定でTHETAのWifiに接続します。<br />
AppleWatchの実機にインストールが完了できれば、撮影ボタンが押下可能となります。<br />
ラベルを表示して、セッション取得前は<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">Connecting...</code>から取得後<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">Connected</code>に変更されるとしています。</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="動画は" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#%E5%8B%95%E7%94%BB%E3%81%AF" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>動画は?</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
もちろんあります。<br />
撮影モード(captureMode)の設定を<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">_video</code>に設定してPOSTリクエストを送ればOK<br />
静止画撮影モードに戻す際は<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">"captureMode": "image"</code>に</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"><span class="k" style="box-sizing: border-box; font-weight: bold;"> let</span> <span class="n" style="box-sizing: border-box;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera.setOptions"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"options"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"captureMode"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"_video"</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
撮影スタートのパラメータはこちら</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera._startCapture"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
撮影ストップのパラメータはこちら</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera._stopCapture"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
撮影モードは維持されるので、動画撮影ストップしたら、<br />
静止画撮影モードに戻した方がベターです。<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">"captureMode": "image"</code>に</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
今回はサンプル実装ですので、エラー処理は未実装、API共通処理など、リファクタリングされていませんがご了承ください。<br />
<br />
<span style="background-color: white; color: #4a4a4a; font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif; font-size: 16px; line-height: 30px;">今回のサンプルに使用しているAPIの詳細はこちらから</span><br />
<a href="https://developers.theta360.com/ja/docs/v2/api_reference/getting_started.html" style="background-color: white; box-sizing: border-box; color: #337ab7; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 30px; text-decoration: none; word-break: break-all; word-wrap: break-word;">Getting Started · API Reference · v2 · API & SDK | RICOH THETA Developers</a></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="番外編-jins-memeからtheta-sを操作しました" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#%E7%95%AA%E5%A4%96%E7%B7%A8-jins-meme%E3%81%8B%E3%82%89theta-s%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>番外編 JINS MEMEからTHETA Sを操作しました</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
JinsMEME ESの3点眼位センサーをインプットとして使って、アウトプット先をTHETA Sにしてシャッターを押すという記事を書きました。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="http://yuichi-dev.blogspot.jp/2015/12/jins-meme-theta-s-or.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">【JINS MEME × THETA S】流し目 or まばたきシャッターの実装</a></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="というかapplewatchthetasユーザっているの" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#%E3%81%A8%E3%81%84%E3%81%86%E3%81%8Bapplewatchthetas%E3%83%A6%E3%83%BC%E3%82%B6%E3%81%A3%E3%81%A6%E3%81%84%E3%82%8B%E3%81%AE" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>というかAppleWatch×ThetaSユーザっているの?</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
AppleWatchユーザでかつThetaSを使っているという方がどれくらいいるかわかりませんが、<br />
アプリにして欲しいなどありましたら是非ご連絡ください。喜んでさぶみっとします!</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="おわりに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/74f124c6189addc70ed9#%E3%81%8A%E3%82%8F%E3%82%8A%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>おわりに</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
以上でAppleWatchからTheta Sをリモート操作は終わりです。<br />
Theta Sは比較的容易にAPI操作でコントロールできることがわかったかと思います。<br />
今回やったことはThetaでできることの序盤です。もっとおもしろいことはできると思います。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
暫くスリープさせずに撮影するオプションなどあるので屋外にずっと置いて定点ストリーミングとか、撮影する画像のサイズを変更したり、ホワイトバランス、<br />
露出補正、画像加工フィルター、シャッタースピードを変更したり、GPS情報を付与する、360度リアルタイムストリーミングとか。リアルウォーリーを探せゲームをつくるとか:)<br />
やっぱりVRデバイスでリアルタイムストリーミングliveとか見れたら一番おもしろいな〜なんて思います。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
今後こういった全天球360度撮影できるカメラはこれから続々と出てくる中、<br />
また一般市場にVRデバイスが発売され始め、2016年はVR元年と言われているくらいなので、続々とおもしろい実写コンテンツがででくるのではないかというのが来年の楽しみです。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
ではまた。</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-85546593786348015852015-12-17T18:31:00.000+09:002015-12-18T18:23:35.154+09:00姿勢監視チェッカー作ってみた<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
by JINS MEME<br />
<a href="http://qiita.com/advent-calendar/2015/jinsmeme" style="background-color: transparent; box-sizing: border-box; color: #23527c; outline: 0px; word-break: break-all; word-wrap: break-word;">JINS MEME Advent Calendar 2015</a> 17日目の記事です。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/29be6166-de97-5f9e-d43a-62e0fe3a845b.gif" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="姿勢監視.gif" src="https://qiita-image-store.s3.amazonaws.com/0/8972/29be6166-de97-5f9e-d43a-62e0fe3a845b.gif" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="姿勢監視.gif" /></a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="jinsmeme-philipshue" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/be751167c56364e0a348#jinsmeme-philipshue" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>JinsMEME × PhilipsHue</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
JinsMEMEの加速度センサーをインプットとして使って、アウトプット先をPhilipsHueのLEDライトにして、猫背になったら赤く点滅し、正しい姿勢になるとアラートなしの通常のライトに戻るというのを作ってみました。<br />
<br /></div>
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/Ok5e2bnnWtQ" width="560"></iframe>
<br />
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="デスクワーカーのために" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/be751167c56364e0a348#%E3%83%87%E3%82%B9%E3%82%AF%E3%83%AF%E3%83%BC%E3%82%AB%E3%83%BC%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>デスクワーカーのために</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
ホワイトカラー、デスクワーカーのために。<br />
PCでの長時間仕事をするとなるとどうしても、背中が曲がってきがちです。<br />
猫背になると赤く点滅させるという物理的な現象を発生させ、まわりの人の迷惑にならないように、意識します。<br />
またライトがちかちかして鬱陶しいので、反射的に良い姿勢を維持しようとするのでよいです。<span style="line-height: 1.875;">猫背にも前傾猫背や後傾猫背など左右のねじれなどがあると思いますが、今回は前傾になった際に加速度センサーx軸のある一定の敷居値を超えたらという判定でアラートしています。</span></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
日常的に姿勢を観察し、正しい姿勢を維持することによって、腰痛の予防や、日々の姿勢を見直すきっかけになればいいなと思っています。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="仕組み" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/be751167c56364e0a348#%E4%BB%95%E7%B5%84%E3%81%BF" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>仕組み</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
JINS MEME→iOS→Philips Hue<br />
JINS MEMEからiOSにBluetoothでデータを送信、<br />
iOS側データを取得、iOSからwifi経由でPhilips Hueを操作</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
言語はSwiftで書き、Hueを操作するためのSDKを利用しています。<br />
The hue Apple SDK by Philips<br />
<a class="autolink" href="https://github.com/PhilipsHue/PhilipsHueSDK-iOS-OSX" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://github.com/PhilipsHue/PhilipsHueSDK-iOS-OSX</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="必要なもの環境" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/be751167c56364e0a348#%E5%BF%85%E8%A6%81%E3%81%AA%E3%82%82%E3%81%AE%E7%92%B0%E5%A2%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>必要なもの、環境</h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">JINS MEME ES or MT <a class="autolink" href="https://jins-meme.com/ja/collection/es/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://jins-meme.com/ja/collection/es/</a></li>
<li style="box-sizing: border-box;">Philips Hue LED <a class="autolink" href="http://www2.meethue.com/ja-jp/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://www2.meethue.com/ja-jp/</a></li>
<li style="box-sizing: border-box;">iOS 9.0+</li>
<li style="box-sizing: border-box;">Bluetooth 4.0(BLE)</li>
<li style="box-sizing: border-box;">Xcode 7</li>
</ul>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="実装" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/be751167c56364e0a348#%E5%AE%9F%E8%A3%85" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>実装 </h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">新規プロジェクト作成(Swift)</li>
<li style="box-sizing: border-box;">Philips Hue SDKをダウンロード <a class="autolink" href="https://github.com/PhilipsHue/PhilipsHueSDK-iOS-OSX" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://github.com/PhilipsHue/PhilipsHueSDK-iOS-OSX</a> こちらのSDKをベースにHueのbridgeと接続します。</li>
<li style="box-sizing: border-box;">HueSDK_iOS.frameworkとSDKWizardフォルダ(Obj-C)をインポート</li>
<li style="box-sizing: border-box;"><span style="color: #4a4a4a; font-size: 16px; line-height: 1.7;">JinsMEME developerサイトからアプリを作成 </span><a class="autolink" href="https://developers.jins.com/ja/login/?goto=/apps/create/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://developers.jins.com/ja/login/?goto=/apps/create/</a></li>
</ul>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
作成したAppCilentIDとClientSecretを以下の****の場所にセットします。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">AppDelegate.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">application</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">application</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">UIApplication</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">didFinishLaunchingWithOptions</span> <span class="nl" style="box-sizing: border-box;">launchOptions</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">[</span><span class="nl" style="box-sizing: border-box;">NSObject</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">AnyObject</span><span class="p" style="box-sizing: border-box;">]</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">)</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">-></span> <span class="n" style="box-sizing: border-box;">Bool</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">MEMELib</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">setAppClientId</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"*********************"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">clientSecret</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"*********************"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 1em; padding-left: 1.5em;">
<li style="box-sizing: border-box;">SwiftからObjective-Cのクラスを利用するためにBridging-Header.hを作成 HueSDK_iOSとSDKWizardの中のPHLoadingViewController,PHBridgeSelectionViewController,PHBridgePushLinkViewController プラス Meme用にMEMELibを記述</li>
</ul>
<div class="code-frame" data-lang="c" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">Bridging-Header.h</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"><span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;">#ifndef Bridging_Header_h</span>
<span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;">#define Bridging_Header_h</span>
<span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;">#import "PHLoadingViewController.h"</span>
<span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;">#import "PHBridgeSelectionViewController.h"</span>
<span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;">#import "PHBridgePushLinkViewController.h"</span>
<span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;">#import <huesdk_ios uesdk.h=""></huesdk_ios></span>
<span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;">#import <memelib ib.h=""></memelib></span>
<span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;">#endif </span><span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;">/* Bridging_Header_h */</span><span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;"></span>
</pre>
</div>
</div>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">AppDelegate.swiftを以下の通りに 中身はHueの初期化、bridgeとの接続などです。 長いのでGistにしています。こちらをご覧ください <a class="autolink" href="https://gist.github.com/manchan/106f4b6108c737df15dc" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://gist.github.com/manchan/106f4b6108c737df15dc</a></li>
<li style="box-sizing: border-box;"><span style="color: #4a4a4a;"><span style="line-height: 27.2px;">Jins Memeのサンプルはこちら(Swift)<a href="https://github.com/manchan/JinsMeme-Swift-Sample" target="_blank">https://github.com/manchan/JinsMeme-Swift-Sample </a></span></span></li>
</ul>
<div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="hue-bridgeとの接続" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/be751167c56364e0a348#hue-bridge%E3%81%A8%E3%81%AE%E6%8E%A5%E7%B6%9A" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>Hue bridgeとの接続</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
詳細に関してはこちらをご覧ください。<br />
<a class="autolink" href="http://www.developers.meethue.com/documentation/apple-api-guide" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://www.developers.meethue.com/documentation/apple-api-guide</a></div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="猫背になったらアラート" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/be751167c56364e0a348#%E7%8C%AB%E8%83%8C%E3%81%AB%E3%81%AA%E3%81%A3%E3%81%9F%E3%82%89%E3%82%A2%E3%83%A9%E3%83%BC%E3%83%88" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>猫背になったら、アラート</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
MEMEからのリアルタイムデータ取得の部分と、Hueのライト変更箇所を抜粋<br />
ライセンスはMITです。ご自由にどうぞ。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">MMDataViewController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">memeRealTimeData</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">MEMERealTimeData</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">memeRealTimeModeDataReceived</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">MEMERealTimeData</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">memeRealTimeData</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">d</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">memeRealTimeData</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">MEMERealTimeData</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 猫背判定</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">accX</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">accX</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">Int</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">accX</span><span class="p" style="box-sizing: border-box;">)</span> <span class="o" style="box-sizing: border-box; font-weight: bold;"><=</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">-</span><span class="mi" style="box-sizing: border-box; color: #009999;">3</span><span class="p" style="box-sizing: border-box;">){</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// red</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">updateLight</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #009999;">0</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">isAlert</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">isRandom</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">updateLight</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">hueValue</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">Int</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">isAlert</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">Bool</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">isRandom</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">Bool</span><span class="p" style="box-sizing: border-box;">){</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">cache</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">PHBridgeResourcesReader</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">readBridgeResourcesCache</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">bridgeSendAPI</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">PHBridgeSendAPI</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">for</span> <span class="n" style="box-sizing: border-box;">light</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span> <span class="n" style="box-sizing: border-box;">cache</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">lights</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">values</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// don't update state of non-reachable lights</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">light</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">lightState</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">reachable</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">==</span> <span class="mi" style="box-sizing: border-box; color: #009999;">0</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">continue</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">lightState</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">PHLightState</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">light</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">type</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">==</span> <span class="n" style="box-sizing: border-box;">DIM_LIGHT</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// Lux bulbs just get a random brightness</span>
<span class="n" style="box-sizing: border-box;">lightState</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">brightness</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">Int</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arc4random</span><span class="p" style="box-sizing: border-box;">())</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">%</span> <span class="mi" style="box-sizing: border-box; color: #009999;">254</span>
<span class="p" style="box-sizing: border-box;">}</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">else</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// アラートの場合</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">isAlert</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 点滅中</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">lightState</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">alert</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">==</span> <span class="n" style="box-sizing: border-box;">ALERT_SELECT</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">break</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">lightState</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">alert</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">ALERT_SELECT</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// ランダム点灯</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">isRandom</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">lightState</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">hue</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">Int</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arc4random</span><span class="p" style="box-sizing: border-box;">())</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">%</span> <span class="mi" style="box-sizing: border-box; color: #009999;">65535</span>
<span class="p" style="box-sizing: border-box;">}</span><span class="k" style="box-sizing: border-box; font-weight: bold;">else</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">lightState</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">hue</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">hueValue</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">lightState</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">brightness</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="mi" style="box-sizing: border-box; color: #009999;">254</span>
<span class="n" style="box-sizing: border-box;">lightState</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">saturation</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="mi" style="box-sizing: border-box; color: #009999;">254</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// Send lightstate to light</span>
<span class="n" style="box-sizing: border-box;">bridgeSendAPI</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">updateLightStateForId</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">light</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">identifier</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">withLightState</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">lightState</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">completionHandler</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">errors</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">[</span><span class="n" style="box-sizing: border-box;">AnyObject</span><span class="p" style="box-sizing: border-box;">]</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">)</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">-></span> <span class="p" style="box-sizing: border-box;">()</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">errors</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">!=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">message</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">String</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">format</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">NSLocalizedString</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Errors %@"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">comment</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">""</span><span class="p" style="box-sizing: border-box;">),</span> <span class="n" style="box-sizing: border-box;">errors</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Response: \(message)"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">})</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="ビルド実行" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/be751167c56364e0a348#%E3%83%93%E3%83%AB%E3%83%89%E5%AE%9F%E8%A1%8C" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>ビルド実行</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
初期ロード時にHueとの接続、Scanして、MEMEと接続。<br />
MEMEをかけた状態で、前傾姿勢になってみてください。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="今後の展開" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/be751167c56364e0a348#%E4%BB%8A%E5%BE%8C%E3%81%AE%E5%B1%95%E9%96%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>今後の展開</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
今回もJINS MEMEで遊んでみました。JINS MEME × Something(Thing to Thing)というのはいくらでもあります。<br />
今回はローカルでのアラート点灯ですが、インターネット越しにリモートのデバイスを動かすようなことも可能で実装済みですので、公開していきたいと考えています。<br />
AWS IoTでデバイス間の状態を検知して、M2M(Machine to Machine)の世界を実現できるのではないかと、わくわくしています。<br />
<br />
ではまた。</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-40718480893417561472015-12-13T11:23:00.000+09:002015-12-13T11:23:18.047+09:00【Swift】NSXMLParserで文字列にアルファベットや数字、マルチバイト文字が含まれる場合、複数に分かれてパースされる件<section class="markdownContent markdownContent-headingEnabled js-task-list-container clearfix position-relative js-task-list-enabled" id="item-b101b06280a8cbd9808c" itemprop="articleBody" style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; word-wrap: break-word;"><div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
SwiftでXMLをパースする際に、<br style="box-sizing: border-box;" />NSXMLParserを使用するのですが、以下のような要素をパースする際に</div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
例<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;"><ele>aaa あいうえお abcd 春夏秋冬 123</ele></code></div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
マルチバイト+アルファベット文字列が要素内であったとすると、<br style="box-sizing: border-box;" />それぞれ分かれて、一回目aaaで二回目あいうえお、三回目abcdの形で取得できてしまって、<br style="box-sizing: border-box;" />一気に取れないのが不便。</div>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
フラグとかはないので手動で配列に貯めてから、閉じタグを読み込んだ時にreduceで再帰的に足して取得する</div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: inherit; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px; position: relative;">
<span class="fragment" id="実装" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/b101b06280a8cbd9808c#%E5%AE%9F%E8%A3%85" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>実装</h2>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
NSXMLParserDelegateを指定</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">isTitle</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">Bool</span><span class="o" style="box-sizing: border-box; font-weight: bold;">=</span><span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">parsedStrArr</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">Array</span><span class="o" style="box-sizing: border-box; font-weight: bold;"><</span><span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">>!</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">entries</span> <span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSMutableArray</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">tmpEntry</span> <span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSMutableArray</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span>
<span class="kr" style="box-sizing: border-box; font-weight: bold;">override</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">viewDidLoad</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">super</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">viewDidLoad</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="n" style="box-sizing: border-box;">loadRss</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">loadRss</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// Sample feed url</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="nl" style="box-sizing: border-box;">rUrl</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSURL</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSURL</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">string</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"https://hoge.co.jp/feed/?cat=5"</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">rssUrl</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">rUrl</span>
<span class="n" style="box-sizing: border-box;">parser</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSXMLParser</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">contentsOfURL</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">rssUrl</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span>
<span class="n" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">delegate</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">//以下の1行の処理でparse関連の処理が行われる。</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="nl" style="box-sizing: border-box;">success</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">Bool</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">parse</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">success</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"パース成功"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">else</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"パース失敗"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// NSXMLParserDelegate</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// ここから下はParse関連処理</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">parserDidStartDocument</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSXMLParser</span><span class="p" style="box-sizing: border-box;">){</span>
<span class="n" style="box-sizing: border-box;">entries</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSMutableArray</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 開始タグを読み込んだ時よばれる - Start</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSXMLParser</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">didStartElement</span> <span class="nl" style="box-sizing: border-box;">elementName</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">String</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">namespaceURI</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">qualifiedName</span> <span class="nl" style="box-sizing: border-box;">qName</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">attributes</span> <span class="nl" style="box-sizing: border-box;">attributeDict</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">[</span><span class="nl" style="box-sizing: border-box;">NSObject</span> <span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">AnyObject</span><span class="p" style="box-sizing: border-box;">])</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">parsedStrArr</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[]</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">elementName</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">==</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"title"</span><span class="p" style="box-sizing: border-box;">){</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 配列初期化</span>
<span class="n" style="box-sizing: border-box;">tmpEntry</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSMutableArray</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="n" style="box-sizing: border-box;">entries</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">addObject</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">tmpEntry</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">isTitle</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span><span class="p" style="box-sizing: border-box;">;</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">//閉じタグを読み込んだ時よばれる - End</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSXMLParser</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">didEndElement</span> <span class="nl" style="box-sizing: border-box;">elementName</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">String</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">namespaceURI</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">qualifiedName</span> <span class="nl" style="box-sizing: border-box;">qName</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">elementName</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">==</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"title"</span><span class="p" style="box-sizing: border-box;">){</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// reduceによる再帰処理で文字列を足す</span>
<span class="n" style="box-sizing: border-box;">tmpEntry</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">addObject</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">parsedStrArr</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">reduce</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">String</span><span class="p" style="box-sizing: border-box;">())</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">$</span><span class="mi" style="box-sizing: border-box; color: #009999;">0</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">+</span> <span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">$</span><span class="mi" style="box-sizing: border-box; color: #009999;">1</span> <span class="p" style="box-sizing: border-box;">})</span>
<span class="n" style="box-sizing: border-box;">isTitle</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">false</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">//タグ以外のテキストを読み込んだ時(タグとタグ間の文字列)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSXMLParser</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">foundCharacters</span> <span class="nl" style="box-sizing: border-box;">string</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">isTitle</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">&&</span> <span class="n" style="box-sizing: border-box;">tmpEntry</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">!=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">){</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// タイトル内文字列を追加していく</span>
<span class="n" style="box-sizing: border-box;">parsedStrArr</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">append</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">string</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">parserDidEndDocument</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">parser</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSXMLParser</span><span class="p" style="box-sizing: border-box;">){</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// ここで最終処理 entries</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: inherit; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px; position: relative;">
<span class="fragment" id="参考" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/b101b06280a8cbd9808c#%E5%8F%82%E8%80%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>参考</h2>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
[iOS] NSXMLParser で文字列が1つのエレメントで複数に分かれてパースされる<br style="box-sizing: border-box;" /><a class="autolink" href="http://www.kuma-de.com/blog/2012-07-20/3782" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://www.kuma-de.com/blog/2012-07-20/3782</a></div>
<div>
<br /></div>
</section>you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-5155236984037376832015-12-09T11:54:00.000+09:002015-12-09T11:54:33.355+09:00メガネ美女子が流し目でシャッター by JINS MEME<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
<a href="http://qiita.com/advent-calendar/2015/jinsmeme" style="background-color: transparent; box-sizing: border-box; color: #23527c; outline: 0px; word-break: break-all; word-wrap: break-word;">JINS MEME Advent Calendar 2015</a> 9日目の記事です。<br />
釣っぽいタイトルですが、釣りではありません実現可能です。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/bfbdda6d-8521-3fad-dcd8-1373afe994a6.jpeg" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="loveli.jpg" src="https://qiita-image-store.s3.amazonaws.com/0/8972/bfbdda6d-8521-3fad-dcd8-1373afe994a6.jpeg" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="loveli.jpg" /></a><br />
(<a class="autolink" href="https://www.instagram.com/loveli_____/?hl=ja%EF%BC%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://www.instagram.com/loveli_____/?hl=ja)</a></div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="http://yuichi-dev.blogspot.jp/2015/12/jins-meme-theta-s-or.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">前回</a>はRICHO THETA Sのシャッターを流し目で押しました。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
今回はJINS MEME をつけて流し目すると、iPhoneのカメラでシャッターを自動で押します。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<span style="line-height: 1.875;">その写真をInstagramやTwitterやFacebookに投稿します。</span></div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<span style="line-height: 1.875;"><br /></span></div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
前回の記事、<a href="http://yuichi-dev.blogspot.jp/2015/12/jins-meme-theta-s-or.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">【JINS MEME × THETA S】流し目 or まばたきシャッターの実装</a> の反応で、</div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="メガネ女子に使ってほしい" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E3%83%A1%E3%82%AC%E3%83%8D%E5%A5%B3%E5%AD%90%E3%81%AB%E4%BD%BF%E3%81%A3%E3%81%A6%E3%81%BB%E3%81%97%E3%81%84" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>メガネ女子に使ってほしい!!!!</h2>
<blockquote class="twitter-tweet" lang="ja" style="line-height: 1.875;">
<div dir="ltr" lang="ja">
流し目シャッターとな!メガネ女子に使って欲しい。そしてそのままインスタとかにあがるとなお(すみません <a href="https://t.co/D5OBzvkB8N">https://t.co/D5OBzvkB8N</a></div>
— ミトログ (@mito_log) <a href="https://twitter.com/mito_log/status/673734925904797696">2015, 12月 7</a></blockquote>
<div style="line-height: 1.875;">
<script async="" charset="utf-8" src="//platform.twitter.com/widgets.js"></script>
</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
との熱烈な要望がありましたので、やっちゃいました。<br />
是非メガネ女子なかた、要望あればAppStoreに出しますよ!</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
インスタで流し目選手権できたらいいな〜<br />
<br />
<br /></div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span style="line-height: 1.225;">JINS MEMEってなに?</span></h2>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
見た目はいたって普通のメガネ。<br />
ジャイロセンサーなどがあり、視線移動などのデータが取れます。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
一日目の記事が非常にわかりやすく網羅されているかと思います。<br />
<a class="autolink" href="http://qiita.com/mito_log/items/020a87996ed2b9d793e6" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://qiita.com/mito_log/items/020a87996ed2b9d793e6</a><br />
<br />
<br /></div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="なんで流し目でシャッターなの" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E3%81%AA%E3%82%93%E3%81%A7%E6%B5%81%E3%81%97%E7%9B%AE%E3%81%A7%E3%82%B7%E3%83%A3%E3%83%83%E3%82%BF%E3%83%BC%E3%81%AA%E3%81%AE" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>なんで流し目でシャッターなの?</h2>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
流し目セルフィーとでも言い換えられますね。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
TOP画の通り、流し目の方が、優雅でメガネ女子が美しく映えるからです<br />
どこかしら余裕があり、風流があり、、知的でSな雰囲気がなんともたまりません。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/dabe8cd6-1ff0-8097-a6c6-ba5603358b99.jpeg" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="bijyo.jpg" src="https://qiita-image-store.s3.amazonaws.com/0/8972/dabe8cd6-1ff0-8097-a6c6-ba5603358b99.jpeg" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="bijyo.jpg" /></a><br />
※写真はイメージです。これぞ、まさに流し目。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
ウィンクしたら、シャッターとかがいいですが、まだ片目だけのまばたき検知はできない?(動作検証したところ片目だけ、まばたきをしても検知できない)ので、<br />
今後、できるようにしてもらいたいところです。JINSさん!<br />
<br />
<br /></div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="仕組み" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E4%BB%95%E7%B5%84%E3%81%BF" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>仕組み</h2>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
JINS MEMEからリアルタイムに流し目(視線移動、右or左)検知データを取得、<br />
iPhone側のフロントカメラを起動しておいて、流し目トリガーで撮影といったシンプルな流れです。<br />
その後、撮影した静止画をFacebook, Twitter, Instagramに投稿をそれぞれ選択可能。</div>
<h3 style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="流れ" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E6%B5%81%E3%82%8C" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>流れ</h3>
<h4 style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 18px; font-weight: normal; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="その1-アプリ起動後メガネ女子が流し目をする" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E3%81%9D%E3%81%AE1-%E3%82%A2%E3%83%97%E3%83%AA%E8%B5%B7%E5%8B%95%E5%BE%8C%E3%83%A1%E3%82%AC%E3%83%8D%E5%A5%B3%E5%AD%90%E3%81%8C%E6%B5%81%E3%81%97%E7%9B%AE%E3%82%92%E3%81%99%E3%82%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>その1. アプリ起動後、メガネ女子が流し目をする</h4>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/ea696da5-5d75-5a1a-654b-5970c8cb8cc3.jpeg" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="メガネjyoshi.jpg" src="https://qiita-image-store.s3.amazonaws.com/0/8972/ea696da5-5d75-5a1a-654b-5970c8cb8cc3.jpeg" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="メガネjyoshi.jpg" /></a></div>
<h4 style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 18px; font-weight: normal; line-height: 1.4; margin: 1.3em 0px 0.7em;">
</h4>
<h4 style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 18px; font-weight: normal; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="その2-iphone側でシャッターが自動で切られ画像保存" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E3%81%9D%E3%81%AE2-iphone%E5%81%B4%E3%81%A7%E3%82%B7%E3%83%A3%E3%83%83%E3%82%BF%E3%83%BC%E3%81%8C%E8%87%AA%E5%8B%95%E3%81%A7%E5%88%87%E3%82%89%E3%82%8C%E7%94%BB%E5%83%8F%E4%BF%9D%E5%AD%98" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>その2. iPhone側でシャッターが自動で切られ、画像保存</h4>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
これはiPhoneを固定しておいてもいいかと。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
<br /></div>
<h4 style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 18px; font-weight: normal; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="その3-下からメニューがせり上がってくる" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E3%81%9D%E3%81%AE3-%E4%B8%8B%E3%81%8B%E3%82%89%E3%83%A1%E3%83%8B%E3%83%A5%E3%83%BC%E3%81%8C%E3%81%9B%E3%82%8A%E4%B8%8A%E3%81%8C%E3%81%A3%E3%81%A6%E3%81%8F%E3%82%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>その3. 下からメニューがせり上がってくる。</h4>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/1a643aca-9ab5-99ce-54d3-ff1944679147.png" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="IMG_7830 (2).PNG" src="https://qiita-image-store.s3.amazonaws.com/0/8972/1a643aca-9ab5-99ce-54d3-ff1944679147.png" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="IMG_7830 (2).PNG" /></a><br />
インスタグラムの欄を選択</div>
<h4 style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 18px; font-weight: normal; line-height: 1.4; margin: 1.3em 0px 0.7em;">
</h4>
<h4 style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 18px; font-weight: normal; line-height: 1.4; margin: 1.3em 0px 0.7em;">
<span class="fragment" id="その4-instagramで投稿" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E3%81%9D%E3%81%AE4-instagram%E3%81%A7%E6%8A%95%E7%A8%BF" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>その4. Instagramで投稿</h4>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/b27b41ed-7481-b84d-6f4d-073679aced65.png" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="IMG_7831 (2).PNG" src="https://qiita-image-store.s3.amazonaws.com/0/8972/b27b41ed-7481-b84d-6f4d-073679aced65.png" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="IMG_7831 (2).PNG" /></a><br />
そのまま投稿したいところですが、</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
インスタグラムのAPIで直接投稿するようなものは用意されていません。<br />
ですので撮影した写真をそのままInstagramのアプリに渡します。<br />
<br />
<br /></div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="必要なもの環境" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E5%BF%85%E8%A6%81%E3%81%AA%E3%82%82%E3%81%AE%E7%92%B0%E5%A2%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>必要なもの、環境</h2>
<ul style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">JINS MEME ES <a class="autolink" href="https://jins-meme.com/ja/collection/es/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://jins-meme.com/ja/collection/es/</a> ※3点眼位センサーが必須なのでESが必要です。</li>
<li style="box-sizing: border-box;">iOS 9.0+</li>
<li style="box-sizing: border-box;">Bluetooth 4.0(BLE)</li>
<li style="box-sizing: border-box;">Xcode 7</li>
<li style="box-sizing: border-box;">Swift 2.0</li>
</ul>
<div>
<span style="line-height: 27.2px;"><br /></span></div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="実装" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E5%AE%9F%E8%A3%85" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>実装 </h2>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
言語はiOSアプリ開発に使用されるSwift(2.0)で以前の記事でサンプルを書きましたがそちらをベースに実装します。<br />
<a class="autolink" href="http://qiita.com/you_matz/items/4f0f83289cb5f4ee5980" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://qiita.com/you_matz/items/4f0f83289cb5f4ee5980</a><br />
JINS MEMEとの接続などはこちらをベースに</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
実装は以下のgistを確認ください。<br />
流し目でシャッター音はなりますが、なしの実装も可能ではありますが審査でrejectされるおそれがありますよ。<br />
<a class="autolink" href="https://gist.github.com/manchan/d270366af589034290d5" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://gist.github.com/manchan/d270366af589034290d5</a><br />
<br />
<br /></div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="反応はいいの-すぐ撮影できるの" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E5%8F%8D%E5%BF%9C%E3%81%AF%E3%81%84%E3%81%84%E3%81%AE-%E3%81%99%E3%81%90%E6%92%AE%E5%BD%B1%E3%81%A7%E3%81%8D%E3%82%8B%E3%81%AE" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>反応はいいの? すぐ撮影できるの?</h2>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
今回はメガネからデータ送信→iOSで取得なのですぐです。<br />
JINS MEMEはiOSデバイスとBluetooth通信で約20Hzの周期、つまり0.05秒毎にリアルタイムデータ送信なので、<br />
<a href="http://yuichi-dev.blogspot.jp/2015/12/jins-meme-theta-s-or.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">wifi経由で操作するTHETA Sの時</a>とは違って、即撮影が可能です。<br />
<br />
<br /></div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="おわりに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/89936a5a6b1ba9956c17#%E3%81%8A%E3%82%8F%E3%82%8A%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>おわりに</h2>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; word-wrap: break-word;">
以上でメガネ美女子が流し目でシャッター by JINS MEMEは終わりです。<br />
今回もJINS MEMEを使って遊んでみました。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<br />
MEME女子の方いましたら是非アプリ化しますので、ご連絡くださいw<br />
もちろん、それ以外の方も、iPhoneを固定した場所に置いて、<br />
JINS MEMEを使って流し目で定点セルフィーしたいなどご要望があれば、ご連絡ください。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
これからもJINS MEMEで遊んでいきます。<br />
この投稿を読んでJINS MEME欲しい!おもしろそう!なにかやりたい!と思ってくれる方がいれば幸いです。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
ではまた。</div>
</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-71300798631877773382015-12-07T10:01:00.001+09:002015-12-23T22:04:08.578+09:00【JINS MEME × THETA S】流し目 or まばたきシャッターの実装<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<a href="http://qiita.com/advent-calendar/2015/jinsmeme" style="box-sizing: border-box; color: #337ab7; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; text-decoration: none; word-break: break-all; word-wrap: break-word;">JINS MEME Advent Calendar 2015</a><span style="font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;"> 7日目の記事です。昨日の記事は</span><a class="user-mention" href="https://qiita.com/mito_log" style="box-sizing: border-box; color: #337ab7; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; text-decoration: none; word-break: break-all; word-wrap: break-word;" title="mito_log">@mito_log</a><span style="font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;">さんによる </span><a href="http://qiita.com/mito_log/items/09df58a6deb926bb58ea" style="box-sizing: border-box; color: #337ab7; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; text-decoration: none; word-break: break-all; word-wrap: break-word;">JINS MEMEのデータをxx秒おきにGoogle SpreadSheetに流す</a><span style="font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;">でした。</span><br />
<span style="font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;"><br /></span><span style="font-family: "helvetica neue" , "helvetica" , "ヒラギノ角ゴ pron w3" , "hiragino kaku gothic pron" , , "meiryo" , sans-serif;">今回はJinsMEME ESの3点眼位センサーをインプットとして使って、アウトプット先を最近購入したTHETA Sで遊んでみようかなと思い、実装してみました。</span><br />
JINS MEMEは、どこを見ているかという視線判定とまばたきの早さ、強さというデータが取れるのが魅力的です。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
今回は流し目(右か左)に視線移動するとTHETA Sのシャッターを押すという誰得なことをやります。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="jins-memeってなに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#jins-meme%E3%81%A3%E3%81%A6%E3%81%AA%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>JINS MEMEってなに?</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
一日目の記事が非常にわかりやすく網羅されているかと思います。<br />
<a class="autolink" href="http://qiita.com/mito_log/items/020a87996ed2b9d793e6" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://qiita.com/mito_log/items/020a87996ed2b9d793e6</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/e5a8de58-c1d8-57ed-b878-121b0a02cc94.png" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="s_スクリーンショット 2015-11-26 午後4.56.49.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/e5a8de58-c1d8-57ed-b878-121b0a02cc94.png" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="s_スクリーンショット 2015-11-26 午後4.56.49.png" /></a><br />
(<a class="autolink" href="https://jins-meme.com/ja/%EF%BC%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://jins-meme.com/ja/)</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="theta-sってなに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#theta-s%E3%81%A3%E3%81%A6%E3%81%AA%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>THETA Sってなに?</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
全天球の360度の写真、動画が取れるカメラデバイスです。<br />
RICOH THETA Advent Calendarの一日目の記事を参考にしてください。<br />
<a class="autolink" href="http://panora.tokyo/3945/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://panora.tokyo/3945/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
どんな写真をとっても360度で撮れるので、おもしろいです。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
写真を見たほうがわかりやすいので、京都の紅葉の写真と市内一望の写真をあげていますのでこちらを見てグリグリ触って確認してみてください。下の写真にフォーカスを当てて、キーボードの上下左右を押しても360度、見ることができますよ!</div>
<blockquote class="ricoh-theta-spherical-image" data-height="400" data-width="750">
京都は今年最後の紅葉風景です。 また来年。 #theta360 - <a href="https://theta360.com/s/ggfzOctuek5ARYlqD8XjEEev6" target="_blank">Spherical Image - RICOH THETA</a></blockquote>
<script async="" charset="utf-8" src="https://theta360.com/widgets.js"></script>
<br />
<blockquote class="ricoh-theta-spherical-image" data-height="400" data-width="750">
京都市内一望 #theta360 - <a href="https://theta360.com/s/hRkoZjFoeTMVnyj8j8goCrjd6" target="_blank">Spherical Image - RICOH THETA</a></blockquote>
<script async="" charset="utf-8" src="https://theta360.com/widgets.js"></script>
<br />
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<span style="font-size: 22px; line-height: 1.225;"><br /></span></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<span style="font-size: 22px; line-height: 1.225;"><br /></span></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<span style="font-size: 22px; line-height: 1.225;">なんで流し目でシャッターなの?</span></div>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">THETA Sはボタンを押したらすぐ写真がとれるのですが、どうしても指が写ってしまう。</li>
<li style="box-sizing: border-box;">上記の紅葉の写真みたいにスマホアプリからシャッター押せますがどうしてもうつむきがちになって顔が映らない</li>
<li style="box-sizing: border-box;">JinsMEMEでまばたき検出したら撮影でもいいが、連写しすぎちゃうので。まばたきの速さと強さで強くor弱くまばたきすればシャッターというのは実装しましたが、わかりやすいのは視線移動かなと思ったので。</li>
</ul>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
という理由から流し目したら、シャッターを押すということに決めました。<br />
それでもまぁまぁな頻度で流し目はするので、右向いて左向いたらシャッターとかでもいいと思います。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="仕組み" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#%E4%BB%95%E7%B5%84%E3%81%BF" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>仕組み</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
ざっくり言うとJinsMEMEからiOSにBluetoothでデータを送信、<br />
iOS側データを取得、iOSからwifi経由でTHETA Sを操作<br />
THETAはHTTPサーバとして動作し、APIリクエストを送って操作ができます。<br />
詳細はこちら。現時点(2015年12月6日)での<br />
RICHO THETA API v2 Reference<br />
<a class="autolink" href="https://developers.theta360.com/ja/docs/v2/api_reference/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://developers.theta360.com/ja/docs/v2/api_reference/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
言語はSwiftで以前の記事でサンプルを書きましたがそちらをベースに実装します。<br />
<a class="autolink" href="http://qiita.com/you_matz/items/4f0f83289cb5f4ee5980" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://qiita.com/you_matz/items/4f0f83289cb5f4ee5980</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="必要なもの環境" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#%E5%BF%85%E8%A6%81%E3%81%AA%E3%82%82%E3%81%AE%E7%92%B0%E5%A2%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>必要なもの、環境</h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">JINS MEME ES <a class="autolink" href="https://jins-meme.com/ja/collection/es/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://jins-meme.com/ja/collection/es/</a></li>
<li style="box-sizing: border-box;">THETA S <a class="autolink" href="https://theta360.com/ja/about/theta/s.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://theta360.com/ja/about/theta/s.html</a></li>
<li style="box-sizing: border-box;">iOS 9.0+</li>
<li style="box-sizing: border-box;">Bluetooth 4.0(BLE)</li>
<li style="box-sizing: border-box;">Xcode 7</li>
<li style="box-sizing: border-box;">Swift 2.0</li>
</ul>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="実装" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#%E5%AE%9F%E8%A3%85" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>実装 </h2>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 24px 0px 0.7em;">
<span class="fragment" id="下準備" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#%E4%B8%8B%E6%BA%96%E5%82%99" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>下準備</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
こちらからJins Memeのサンプルをダウンロード<br />
<a class="autolink" href="https://github.com/manchan/JinsMeme-Swift-Sample" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://github.com/manchan/JinsMeme-Swift-Sample</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
JinsMEME developerサイトからアプリを作成<br />
<a class="autolink" href="https://developers.jins.com/ja/login/?goto=/apps/create/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://developers.jins.com/ja/login/?goto=/apps/create/</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
作成したAppCilentIDとClientSecretを以下の****の場所にセットします。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">AppDelegate.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">application</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">application</span><span class="p" style="box-sizing: border-box;">:</span> <span class="bp" style="box-sizing: border-box; color: #999999;">UIApplication</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">didFinishLaunchingWithOptions</span> <span class="nl" style="box-sizing: border-box;">launchOptions</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">[</span><span class="nl" style="box-sizing: border-box;">NSObject</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">AnyObject</span><span class="p" style="box-sizing: border-box;">]</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span><span class="p" style="box-sizing: border-box;">)</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">-></span> <span class="n" style="box-sizing: border-box;">Bool</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">MEMELib</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">setAppClientId</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"*********************"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">clientSecret</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"*********************"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
THETA Sのシャッターを押すために、<br />
HTTPネットワークライブラリであるAlamofireを利用します。</div>
<div class="code-frame" data-lang="Podfile" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;">use_frameworks!
pod 'Alamofire', '~> 2.0'
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="theta-sとのセッションの開始" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#theta-s%E3%81%A8%E3%81%AE%E3%82%BB%E3%83%83%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E9%96%8B%E5%A7%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>THETA Sとのセッションの開始</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
デバイスとのセッションを開始し、sessionIdを取得します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">MMDataViewController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"><span class="k" style="box-sizing: border-box; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">Alamofire</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">ssid</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span>
<span class="kr" style="box-sizing: border-box; font-weight: bold;">override</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">viewDidLoad</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">super</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">viewDidLoad</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="n" style="box-sizing: border-box;">sessionStart</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// セッション開始</span>
<span class="n" style="box-sizing: border-box;">private</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="n" style="box-sizing: border-box;">sessionStart</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera.startSession"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="n" style="box-sizing: border-box;">Alamofire</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">request</span><span class="p" style="box-sizing: border-box;">(.</span><span class="n" style="box-sizing: border-box;">POST</span><span class="p" style="box-sizing: border-box;">,</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"http://192.168.1.1/osc/commands/execute"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">encoding</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">JSON</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">responseJSON</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">switch</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Success</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data_dic</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSDictionary</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">ssid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data_dic</span><span class="p" style="box-sizing: border-box;">[</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"results"</span><span class="p" style="box-sizing: border-box;">]</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">[</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="p" style="box-sizing: border-box;">]</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span> <span class="n" style="box-sizing: border-box;">String</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">ssid</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Failure</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">,</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">error</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Request failed with error: \(error)"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="theta-sで静止画撮影" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#theta-s%E3%81%A7%E9%9D%99%E6%AD%A2%E7%94%BB%E6%92%AE%E5%BD%B1" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>THETA Sで静止画撮影</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
静止画撮影するためのメソッドです。<br />
セッション開始して、取得したsessionIdを利用します。<br />
撮影に成功すると、takePicture Success!!とアラートを出します。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">MMDataViewController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 静止画撮影</span>
<span class="n" style="box-sizing: border-box;">private</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="nf" style="box-sizing: border-box; color: #990000; font-weight: bold;">takePicture</span><span class="p" style="box-sizing: border-box;">(){</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera.takePicture"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="n" style="box-sizing: border-box;">Alamofire</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">request</span><span class="p" style="box-sizing: border-box;">(.</span><span class="n" style="box-sizing: border-box;">POST</span><span class="p" style="box-sizing: border-box;">,</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"http://192.168.1.1/osc/commands/execute"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">encoding</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">JSON</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">responseJSON</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">switch</span> <span class="n" style="box-sizing: border-box;">result</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Success</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data_dic</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">data</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSDictionary</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"takePicture Success!!"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="bp" style="box-sizing: border-box; color: #999999;">UIAlertView</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"撮影test"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">message</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"takePicture Success!!"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">delegate</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">cancelButtonTitle</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"OK"</span><span class="p" style="box-sizing: border-box;">).</span><span class="n" style="box-sizing: border-box;">show</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Failure</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">,</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">error</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="n" style="box-sizing: border-box;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Request failed with error: \(error)"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="jins-memeからリアルタイムデータの取得視線移動からシャッター" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#jins-meme%E3%81%8B%E3%82%89%E3%83%AA%E3%82%A2%E3%83%AB%E3%82%BF%E3%82%A4%E3%83%A0%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AE%E5%8F%96%E5%BE%97%E8%A6%96%E7%B7%9A%E7%A7%BB%E5%8B%95%E3%81%8B%E3%82%89%E3%82%B7%E3%83%A3%E3%83%83%E3%82%BF%E3%83%BC" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>JINS MEMEからリアルタイムデータの取得,視線移動からシャッター</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
memeRealTimeModeDataReceivedメソッドから取得したリアルタイムデータを利用します。<br />
tableViewのcellForRowAtIndexPathデリゲートメソッドから視線を右に動かした箇所を抜粋</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">MMDataViewController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="mi" style="box-sizing: border-box; color: #009999;">6</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;">/****************</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;"> 視線が右に動いたかどうかを示す整数値</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;"> 0:なし</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;"> 1:移動検知ー小</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;"> 2:移動検知ー中</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;"> 3:逆移動検知ー大</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;"> 4:逆移動検知ー特大</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;"> ****************/</span>
<span class="n" style="box-sizing: border-box;">label</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"Eye Move Right"</span><span class="p" style="box-sizing: border-box;">;</span>
<span class="n" style="box-sizing: border-box;">value</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSString</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">format</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"%d"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">eyeMoveRight</span><span class="p" style="box-sizing: border-box;">)</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">String</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">value</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">!=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"0"</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">takePicture</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">alertController</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">UIAlertController</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"右移動"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">message</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">""</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">preferredStyle</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Alert</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">cancelAction</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">UIAlertAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"Cancel"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">style</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Cancel</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">action</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">UIAlertAction</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">)</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">alertController</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">addAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">cancelAction</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">OKAction</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">UIAlertAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"OK"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">style</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Default</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">action</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">UIAlertAction</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">)</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">alertController</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">addAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">OKAction</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">presentViewController</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">alertController</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">animated</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">completion</span><span class="p" style="box-sizing: border-box;">:</span><span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">break</span>
</pre>
</div>
</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
視線が右に動いた場合、シャッターを押し、右移動というアラートを出しています。<br />
これで、JINS MEME×THETA Sで静止画を撮影するということが可能となります。</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="ビルド実行" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#%E3%83%93%E3%83%AB%E3%83%89%E5%AE%9F%E8%A1%8C" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>ビルド実行</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
THETA Sの電源を入れ、iPhoneのWifi設定でTHETAのWifiに接続します。<br />
その後、ビルド実行して、JINS MEMEデバイスとの接続で完了。<br />
視線移動して、試してみてください。<br />
<br />
<h3 style="box-sizing: border-box; color: inherit; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em; position: relative;">
シャッターを無音にしたい場合(2015/12/13追記)</h3>
<div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
_shutterVolumeを0にすることで、シャッター音なしも可能となります。<br />
デフォルトで音量は100になっています。</div>
<br />
<h3 style="box-sizing: border-box; color: inherit; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em; position: relative;">
<span class="fragment" id="番外編弱まばたきでシャッター" style="box-sizing: border-box; display: block; line-height: 28.6px; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/5b972d9c247e91ecb83c#%E7%95%AA%E5%A4%96%E7%B7%A8%E5%BC%B1%E3%81%BE%E3%81%B0%E3%81%9F%E3%81%8D%E3%81%A7%E3%82%B7%E3%83%A3%E3%83%83%E3%82%BF%E3%83%BC" style="box-sizing: border-box; color: #337ab7; line-height: 28.6px; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a></h3>
<br />
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; font-weight: 400; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">MMDataViewController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; display: block; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; margin: 0px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; white-space: pre; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="nf" style="box-sizing: border-box; color: #990000; font-weight: bold;">setShutterVolumeZero</span><span class="p" style="box-sizing: border-box;">()</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box; color: #333333;">parameters</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"name"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"camera.setOptions"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"parameters"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"sessionId"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box; color: #333333;">ssid</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"options"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span> <span class="p" style="box-sizing: border-box;">[</span>
<span class="s" style="box-sizing: border-box; color: #dd1144;">"_shutterVolume"</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span><span class="mi" style="box-sizing: border-box; color: #009999;">0</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="p" style="box-sizing: border-box;">]</span>
<span class="n" style="box-sizing: border-box; color: #333333;">Alamofire</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box; color: #333333;">request</span><span class="p" style="box-sizing: border-box;">(.</span><span class="n" style="box-sizing: border-box; color: #333333;">POST</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box; color: #333333;">commandExecURL</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">parameters</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box; color: #333333;">parameters</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">encoding</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box; color: #333333;">JSON</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box; color: #333333;">responseJSON</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="n" style="box-sizing: border-box; color: #333333;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box; color: #333333;">_</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box; color: #333333;">result</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">switch</span> <span class="n" style="box-sizing: border-box; color: #333333;">result</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box; color: #333333;">Success</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box; color: #333333;">data</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box; color: #333333;">data_dic</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box; color: #333333;">data</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSDictionary</span>
<span class="n" style="box-sizing: border-box; color: #333333;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box; color: #333333;">data_dic</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box; color: #333333;">Failure</span><span class="p" style="box-sizing: border-box;">(</span><span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box; color: #333333;">data</span><span class="p" style="box-sizing: border-box;">,</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box; color: #333333;">error</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="n" style="box-sizing: border-box; color: #333333;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: #dd1144;">"Request failed with error: \(error)"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="番外編弱まばたきでシャッター" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#%E7%95%AA%E5%A4%96%E7%B7%A8%E5%BC%B1%E3%81%BE%E3%81%B0%E3%81%9F%E3%81%8D%E3%81%A7%E3%82%B7%E3%83%A3%E3%83%83%E3%82%BF%E3%83%BC" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>番外編(弱まばたきでシャッター)</h3>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
まばたきのスピードでゆっくりまばたきしたら、撮影しますか?というアラートを出して、<br />
OKを押すと、シャッターを押します。アラートは別になしでもいいかと思います。</div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="code-lang" style="background-color: rgba(0, 0, 0, 0.0666667); box-sizing: border-box; color: #555555; display: inline-block; font-size: 12px; line-height: 1; margin: 0px; padding: 3px 6px;">
<span class="bold" style="box-sizing: border-box;">MMDataViewController.swift</span></div>
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow-x: scroll; overflow-y: auto; padding: 8px 15px; word-break: break-all; word-wrap: normal;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">case</span> <span class="mi" style="box-sizing: border-box; color: #009999;">8</span><span class="o" style="box-sizing: border-box; font-weight: bold;">:</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;">/****************</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;"> まばたきのスピード(Millisecond)</span>
<span class="cm" style="box-sizing: border-box; color: #999988; font-style: italic;"> ****************/</span>
<span class="n" style="box-sizing: border-box;">label</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"Blink Speed"</span><span class="p" style="box-sizing: border-box;">;</span>
<span class="n" style="box-sizing: border-box;">value</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSString</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">format</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"%d"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">data</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">blinkSpeed</span><span class="p" style="box-sizing: border-box;">)</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">String</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 50以下であれば</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">Int</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">value</span><span class="p" style="box-sizing: border-box;">)</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">!=</span> <span class="mi" style="box-sizing: border-box; color: #009999;">0</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">&&</span> <span class="n" style="box-sizing: border-box;">Int</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">value</span><span class="p" style="box-sizing: border-box;">)</span> <span class="o" style="box-sizing: border-box; font-weight: bold;"><</span> <span class="mi" style="box-sizing: border-box; color: #009999;">50</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">alertController</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">UIAlertController</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"撮影しますか?"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">message</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">""</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">preferredStyle</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Alert</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">cancelAction</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">UIAlertAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"Cancel"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">style</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Cancel</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">action</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">UIAlertAction</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">)</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">alertController</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">addAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">cancelAction</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">OKAction</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">UIAlertAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"OK"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">style</span><span class="p" style="box-sizing: border-box;">:</span> <span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">Default</span><span class="p" style="box-sizing: border-box;">)</span> <span class="p" style="box-sizing: border-box;">{</span> <span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">action</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">UIAlertAction</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">)</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">in</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">sid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">ssid</span> <span class="kt" style="box-sizing: border-box; color: #445588; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">takePicture</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">alertController</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">addAction</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">OKAction</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">self</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">presentViewController</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">alertController</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">animated</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">true</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">completion</span><span class="p" style="box-sizing: border-box;">:</span><span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">break</span>
</pre>
</div>
</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="ぶっちゃけ反応どうなの" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#%E3%81%B6%E3%81%A3%E3%81%A1%E3%82%83%E3%81%91%E5%8F%8D%E5%BF%9C%E3%81%A9%E3%81%86%E3%81%AA%E3%81%AE" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>ぶっちゃけ反応どうなの?</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
視線を右に動かしてから、シャッターまでやはりタイムラグはあります。<br />
そこはJINS MEME→iOS→THETA SでiOS経由なのでしょうがない部分ではあります。<br />
そこがJINS MEMEのBluetooth→THETAとかに直接コマンド送れれば...もっと反応は早くなるでしょう。でも視線移動から体感一秒以内なので十分なスピードです。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="おわりに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/5b972d9c247e91ecb83c#%E3%81%8A%E3%82%8F%E3%82%8A%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>おわりに</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
以上で【JINS MEME × THETA S】流し目シャッターの実装は終わりです。<br />
まだまだJINS MEME × ハード連携は組み合わせはいくらでもあると思うので、これからもやっていきたいなと思っています。この投稿を読んでJINS MEME or THETA Sが欲しい!おもしろそうと思ってくれる方がいれば幸いです。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
別でAppleWatchからTHETAをコントロールするようなことはしたので、またRICHO THETA Advent Calendarの方で書きます。<br />
<br /></div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-19578533599985572742015-11-30T21:51:00.000+09:002015-11-30T21:51:02.870+09:00AngularJs ✕ Firebaseで爆速イメージストア環境の作成<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
以前、<a href="http://qiita.com/you_matz/items/0794129893f9eefc24fd" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">AngularJs ✕ Firebaseで爆速リアルタイムアプリケーションの作成</a>という記事を書きましたが、<br />
今回は画像をさくっとどこかにあげて利用したい時、firebaseを使えば、5分で環境が出来ます。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
S3、Parseの利用を検討しましたが、</div>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 1em; padding-left: 1.5em;">
<li style="box-sizing: border-box;">無料</li>
<li style="box-sizing: border-box;">APIドキュメントがわかりやすい(Parseはファイルストレージが20GBだが、ドキュメントがわかりにくい)</li>
<li style="box-sizing: border-box;">リアルタイムにデータ同期しやすい</li>
</ul>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
上記の点でAngularJs×Firebaseを採用。なんといってもリアルタイムデータ同期が魅力的。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
※Milkcocoaは検討してませんw</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="firebaseとは" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#firebase%E3%81%A8%E3%81%AF" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>Firebaseとは</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
いわゆるモバイルBassでWebアプリケーション、モバイル・アプリケーションの開発者向けにリアルタイムにスケーラブルなバックエンドサービスを提供しています。<br />
一定の転送量、接続数、容量は無料で、クレジットなしで使用できます。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
ストレージ1GBまで無料なので、まぁ問題ないレベル。<br />
バックアップは無料プランでは取れません。<br />
<a class="autolink" href="https://www.firebase.com/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://www.firebase.com/</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="angularfire" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#angularfire" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>AngularFire</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
そして、AngularJsからFirebaseを利用できる、<br />
AngularFireというAPIも公開されていますので、<br />
バックエンドのコードを書く必要も、サーバも必要なく、<br />
必要な作業に集中できます。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
AngularFireのAPIを利用することで、<br />
Angularjsのモデルが自動的に同期され、Firebase上でリアルタイムにデータバインディングされます。<br />
これでhtml側でのview, Angularjsでのmodel, firebaseでストアされたjsonのデータの3wayデータバインディングが可能となります。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="angular-file-upload" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#angular-file-upload" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>angular-file-upload</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
FlashによるFileAPI代替を提供するモジュール<br />
HTML5のFileAPIを利用,HTML5のFileAPIサポートしていないブラウザ(IE8、IE9など)にはFlashを利用して同等の機能を提供。<br />
今回はbase64データのURL生成してアップロードしています。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="サンプル画像アップロードアプリ" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E7%94%BB%E5%83%8F%E3%82%A2%E3%83%83%E3%83%97%E3%83%AD%E3%83%BC%E3%83%89%E3%82%A2%E3%83%97%E3%83%AA" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>サンプル:画像アップロードアプリ</h2>
<div class="code-frame" data-lang="html" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
</div>
<script src="https://gist.github.com/0d8597b1ac131d1b1f16.js"></script>
<br />
<div class="code-frame" data-lang="html" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<span style="background-color: white; line-height: 1.875;">わずか110行で簡単イメージストアアプリが作成できます。</span></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">var ref = new Firebase("https://<your-firebase>.firebaseio.com/");</your-firebase></code><br />
上記の箇所をfirebaseにサインアップして、URLを書き換えるだけですぐ使えます。<br />
サインアップはこちらから<br />
<a class="autolink" href="https://www.firebase.com/login/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://www.firebase.com/login/</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="注意" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#%E6%B3%A8%E6%84%8F" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>※注意</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
無料プランでストレージは1GBまでです。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="firebaseにストアされたデータにindexをはる方法" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#firebase%E3%81%AB%E3%82%B9%E3%83%88%E3%82%A2%E3%81%95%E3%82%8C%E3%81%9F%E3%83%87%E3%83%BC%E3%82%BF%E3%81%ABindex%E3%82%92%E3%81%AF%E3%82%8B%E6%96%B9%E6%B3%95" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>Firebaseにストアされたデータにindexをはる方法</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
設定で、json形式でkey,rulesの中に.indexOnを記述するだけ<br />
詳細はこちら<br />
<a class="autolink" href="https://www.firebase.com/docs/security/guide/indexing-data.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://www.firebase.com/docs/security/guide/indexing-data.html</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="firebaseにストアされたデータのセキュリティに関して" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#firebase%E3%81%AB%E3%82%B9%E3%83%88%E3%82%A2%E3%81%95%E3%82%8C%E3%81%9F%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AE%E3%82%BB%E3%82%AD%E3%83%A5%E3%83%AA%E3%83%86%E3%82%A3%E3%81%AB%E9%96%A2%E3%81%97%E3%81%A6" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>Firebaseにストアされたデータのセキュリティに関して</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
jsonでのセキュリティルールの設定が可能。<br />
認証されたユーザがどのようにデータを変更できるかを決める。<br />
データの転送はSSL経由。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
さらなる詳細はこちら<br />
<a class="autolink" href="https://www.firebase.com/docs/security/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://www.firebase.com/docs/security/</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="angularfireの使用アプリ" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#angularfire%E3%81%AE%E4%BD%BF%E7%94%A8%E3%82%A2%E3%83%97%E3%83%AA" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>AngularFireの使用アプリ</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
好きなアーティストの音楽をランキング順の聴くことができるサービスです。<br />
Recentの箇所をfirebaseでストアしています。<br />
Lamusica<br />
<a class="autolink" href="http://manchan.github.io/lamusica/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://manchan.github.io/lamusica/</a><br />
githubはこちら<br />
<a class="autolink" href="https://github.com/manchan/lamusica" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://github.com/manchan/lamusica</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="angularfireのドキュメントはこちら" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#angularfire%E3%81%AE%E3%83%89%E3%82%AD%E3%83%A5%E3%83%A1%E3%83%B3%E3%83%88%E3%81%AF%E3%81%93%E3%81%A1%E3%82%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>AngularFireのドキュメントはこちら</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<a class="autolink" href="https://www.firebase.com/docs/web/libraries/angular/index.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://www.firebase.com/docs/web/libraries/angular/index.html</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="ng-file-uploadのドキュメントはこちら" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#ng-file-upload%E3%81%AE%E3%83%89%E3%82%AD%E3%83%A5%E3%83%A1%E3%83%B3%E3%83%88%E3%81%AF%E3%81%93%E3%81%A1%E3%82%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>ng-file-uploadのドキュメントはこちら</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<a class="autolink" href="https://github.com/danialfarid/ng-file-upload" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://github.com/danialfarid/ng-file-upload</a></div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="おわりに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/f152da60a4ce25135c2c#%E3%81%8A%E3%82%8F%E3%82%8A%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>おわりに</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
5分は長すぎたかもしれません。</div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-56168829839573267642015-11-27T09:10:00.000+09:002015-11-27T09:10:10.465+09:00JINS MEME Swift Sample<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
J!NS MEME Swift Sample</h1>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
Jins MemeのサンプルコードをSwiftで書き、公開しました。<br />
<a class="autolink" href="https://github.com/manchan/JinsMeme-Swift-Sample" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://github.com/manchan/JinsMeme-Swift-Sample</a></div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
<a href="https://qiita-image-store.s3.amazonaws.com/0/8972/e5a8de58-c1d8-57ed-b878-121b0a02cc94.png" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="s_スクリーンショット 2015-11-26 午後4.56.49.png" src="https://qiita-image-store.s3.amazonaws.com/0/8972/e5a8de58-c1d8-57ed-b878-121b0a02cc94.png" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" title="s_スクリーンショット 2015-11-26 午後4.56.49.png" /></a><br />
(<a class="autolink" href="https://jins-meme.com/ja/%EF%BC%89" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://jins-meme.com/ja/)</a></div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
J!NS MEMEから取得できるリアルタイムデータを確認できるサンプルのアプリです。<br />
既存のサンプル(Objective-C)をSwiftに書き換え、それぞれのデータの詳細情報を閲覧できるようにしています。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
ソースコードはGithubに置いてありますので、ご自由にお使い下さい。<br />
JINS MEMEのSDKのバージョンは1.0.5です(2015/11/25現在)</div>
</h1>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="動作環境" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#%E5%8B%95%E4%BD%9C%E7%92%B0%E5%A2%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>動作環境</h2>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<ul style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box;">iOS 9.0+</li>
<li style="box-sizing: border-box;">Bluetooth 4.0(BLE)</li>
<li style="box-sizing: border-box;">J!NS MEMEが必要です。</li>
</ul>
</h1>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="そのままxcodeで実行できますが一から作成するための手順を記述しておきます" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#%E3%81%9D%E3%81%AE%E3%81%BE%E3%81%BExcode%E3%81%A7%E5%AE%9F%E8%A1%8C%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%99%E3%81%8C%E4%B8%80%E3%81%8B%E3%82%89%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B%E3%81%9F%E3%82%81%E3%81%AE%E6%89%8B%E9%A0%86%E3%82%92%E8%A8%98%E8%BF%B0%E3%81%97%E3%81%A6%E3%81%8A%E3%81%8D%E3%81%BE%E3%81%99" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>そのままXcodeで実行できますが一から作成するための手順を記述しておきます。</h2>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
①SDKからMEMELib.frameworkを導入<br />
②Bluetooth権限設定<br />
Capabilities > Background ModesをONにし、 Use Bluetooth LE accessory にチェック<br />
③Bridginging Headerファイル作成<br />
<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">#import <memelib ib.h=""></memelib></code>を記述<br />
Build Settings > Swift Compiler - Code Generationに、Bridging Headerを指定</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
④下記より認証コードを設定<br />
⑤あとはお好きにどうぞ</div>
</h1>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="実行方法" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#%E5%AE%9F%E8%A1%8C%E6%96%B9%E6%B3%95" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>実行方法</h2>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<span style="box-sizing: border-box; font-weight: 900;">Xcode 7</span>でビルドしてください。<br />
こちらよりアプリを作成して <a class="autolink" href="https://developers.jins.com/ja/apps/create/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://developers.jins.com/ja/apps/create/</a><br />
<br style="box-sizing: border-box;" />
取得したアプリID / アプリSecretをMEMELibのsetAppClientIdの引数にセットする必要があります。<code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">AppDelegate.swift</code> at line 20 を書き換えてください。</div>
</h1>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="内容" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#%E5%86%85%E5%AE%B9" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>内容</h2>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<a href="https://raw.githubusercontent.com/manchan/JinsMeme-Swift-Sample/master/ResourcesForREADME/meme2.gif" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;" target="_blank"><img alt="" src="https://raw.githubusercontent.com/manchan/JinsMeme-Swift-Sample/master/ResourcesForREADME/meme2.gif" style="border: 0px; box-sizing: border-box; margin: 0px; max-width: 100%; vertical-align: middle;" /></a></div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="eyemoveup" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#eyemoveup" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>eyeMoveUp</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
視線が上に動いたかどうかを示す整数値</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="eyemovedown" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#eyemovedown" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>eyeMoveDown</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
視線が下に動いたかどうかを示す整数値</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="eyemoveleft" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#eyemoveleft" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>eyeMoveLeft</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
視線が左に動いたかどうかを示す整数値</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="eyemoveright" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#eyemoveright" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>eyeMoveRight</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
視線が右に動いたかどうかを示す整数値</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="blinkspeed" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#blinkspeed" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>blinkSpeed</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
まばたきのスピード(Millisecond)</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="blinkstrength" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#blinkstrength" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>blinkStrength</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
まばたきの強さ (一般的に、50~200の間におさまります。)</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="walking" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#walking" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>walking</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
かかとを地面についたかどうか。それを検出するとtrueになる</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="roll" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#roll" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>roll</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
姿勢を表す角度のうちのロール要素を示す度</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="pitch" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#pitch" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>pitch</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
姿勢を表す角度のうちのピッチ要素を示す度</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="yaw" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#yaw" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>yaw</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
姿勢を表す角度のうちのヨー要素を示す度</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="accx" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#accx" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>accX</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
加速度のX軸の値。-128 ~ 127 の1byteの整数値</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="accy" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#accy" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>accY</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
加速度のY軸の値。-128 ~ 127 の1byteの整数値</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="accz" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#accz" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>accZ</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
加速度のZ軸の値。-128 ~ 127 の1byteの整数値</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="fiterror" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#fiterror" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>fitError</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
JINS MEMEがきちんと装着されているかどうかを示す整数値。</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="powerleft" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#powerleft" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>powerLeft</h3>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
電池残量を表す整数値</div>
</h1>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em;">
<span class="fragment" id="詳細情報はこちらより-jins-memeミーム-developers" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#%E8%A9%B3%E7%B4%B0%E6%83%85%E5%A0%B1%E3%81%AF%E3%81%93%E3%81%A1%E3%82%89%E3%82%88%E3%82%8A-jins-meme%E3%83%9F%E3%83%BC%E3%83%A0-developers" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>詳細情報はこちらより <a href="https://developers.jins.com/ja/resource/docs/startup_guide/ios/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">JINS MEME(ミーム) DEVELOPERS</a>!!</h3>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="おわりに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/4f0f83289cb5f4ee5980#%E3%81%8A%E3%82%8F%E3%82%8A%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>おわりに</h2>
<h1 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 24px; font-weight: normal; line-height: 1.2; margin-bottom: 12px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding-bottom: 8px;">
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
3点式の眼電位センサーが眼の動き(視線)やまばたきを検出してくれるので、<br />
それを利用して、何かアクションを起こすというポインティングデバイスとしての利用がおもしろいなと思います。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
眼電位センサーにより疲れ度合い、眠気、集中度などもデータ解析の仕方によっては推定することが可能になるのかなと思います。実際にJinsサイドはJINS MEME DRIVEという眠気を推定するドライバー向けiOSアプリを公開していますし。</div>
<div style="box-sizing: border-box; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
様々なハードウェアと連携させてなにかできそうです。</div>
</h1>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 1em; padding-left: 1.5em;">
</ul>
<ul class="ul1">
</ul>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-80000765519871956942015-11-20T11:56:00.002+09:002015-11-20T11:56:53.016+09:00Chromeでjsonのkeyを数字にしている場合、勝手に昇順にされる件<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
筆者環境:MacOSX Yosemite, Google Chromeバージョン 46.0.2490.86 (64-bit)<br style="box-sizing: border-box;" />表題通り、ありがた迷惑な機能。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
これはV8 JavaScript EngineのECMAScript準拠でバグではない模様。<br style="box-sizing: border-box;" />5年前くらい前から変わっていない。<br style="box-sizing: border-box;" />firefoxでは降順ソートは維持され、問題ないことを確認。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px; position: relative;">
<span class="fragment" id="問題のissue-37404---chromium---chrome-reorders-keys-in-the-dictionary-object-httpbitly1qw0utr" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/c046e9070f211a8bb293#%E5%95%8F%E9%A1%8C%E3%81%AEissue-37404---chromium---chrome-reorders-keys-in-the-dictionary-object-httpbitly1qw0utr" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>問題のIssue 37404 - chromium - Chrome reorders keys in the dictionary (object) <a class="autolink" href="http://bit.ly/1Qw0utr" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://bit.ly/1Qw0utr</a></h2>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px; position: relative;">
<span class="fragment" id="例" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/c046e9070f211a8bb293#%E4%BE%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>例</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
こんな感じに成形して、keyを数字で降順ソートしたが、勝手にkeyで昇順にソートされる。</div>
<div class="code-frame" data-lang="json" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow: auto; padding: 8px 15px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;"><span class="p" style="box-sizing: border-box;">{</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">1444275582:</span> <span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">{</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">url:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"https://instagram.com/p/8j9S8_r_BE/"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">img:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s640x640/sh0.08/e35/12120292_917670381655742_1569021259_n.jpg"</span>
<span class="p" style="box-sizing: border-box;">}</span><span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">,</span>
<span class="mi" style="box-sizing: border-box; color: #009999;">1444545530</span><span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">:</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">url:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"https://instagram.com/p/8sALlWAfUJ/"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">img:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"https://scontent.cdninstagram.com/hphotos-xtp1/t51.2885-15/e15/12106290_1294775143882158_1454631624_n.jpg"</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">}</span>
</pre>
</div>
</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px; position: relative;">
<span class="fragment" id="対策" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/c046e9070f211a8bb293#%E5%AF%BE%E7%AD%96" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>対策</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
created_atのkeyだけで降順ソートでjson成形</div>
<div class="code-frame" data-lang="json" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow: auto; padding: 8px 15px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;"><span class="p" style="box-sizing: border-box;">{</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">{</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">created_at:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"1447984282"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">url:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"https://instagram.com/p/-SfFKzy73D/"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">img:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/ s640x640/sh0.08/e35/12256594_516826635166064_1483786264_n.jpg"</span>
<span class="p" style="box-sizing: border-box;">}</span><span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">,</span>
<span class="p" style="box-sizing: border-box;">{</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">created_at:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"1447984163"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">url:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"https://instagram.com/p/-Se2neyurm/"</span><span class="p" style="box-sizing: border-box;">,</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">img:</span> <span class="nt" style="box-sizing: border-box; color: navy;">"https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/e15/12230899_1538400876451449_364138165_n.jpg"</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="err" style="background-color: #e3d2d2; box-sizing: border-box; color: #a61717;">}</span>
</pre>
</div>
</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px; position: relative;">
<span class="fragment" id="解決方法" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/c046e9070f211a8bb293#%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%B3%95" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>解決方法</h2>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 24px 0px 0.7em; position: relative;">
<span class="fragment" id="バックエンド側でjsonを吐き出す実装を変えるphp" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/c046e9070f211a8bb293#%E3%83%90%E3%83%83%E3%82%AF%E3%82%A8%E3%83%B3%E3%83%89%E5%81%B4%E3%81%A7json%E3%82%92%E5%90%90%E3%81%8D%E5%87%BA%E3%81%99%E5%AE%9F%E8%A3%85%E3%82%92%E5%A4%89%E3%81%88%E3%82%8Bphp" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>バックエンド側でjsonを吐き出す実装を変える(php)</h3>
<div class="code-frame" data-lang="php" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow: auto; padding: 8px 15px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;"><span class="cp" style="box-sizing: border-box; color: #999999; font-weight: bold;">
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// APIから取得したデータを成形</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">foreach</span><span class="p" style="box-sizing: border-box;">(</span><span class="nv" style="box-sizing: border-box; color: teal;">$result</span><span class="p" style="box-sizing: border-box;">[</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"data"</span><span class="p" style="box-sizing: border-box;">]</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">as</span> <span class="nv" style="box-sizing: border-box; color: teal;">$k</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=></span> <span class="nv" style="box-sizing: border-box; color: teal;">$v</span><span class="p" style="box-sizing: border-box;">){</span>
<span class="nv" style="box-sizing: border-box; color: teal;">$insta_arr</span><span class="p" style="box-sizing: border-box;">[</span><span class="nv" style="box-sizing: border-box; color: teal;">$k</span><span class="p" style="box-sizing: border-box;">][</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"created_at"</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nv" style="box-sizing: border-box; color: teal;">$v</span><span class="p" style="box-sizing: border-box;">[</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"created_time"</span><span class="p" style="box-sizing: border-box;">];</span>
<span class="nv" style="box-sizing: border-box; color: teal;">$insta_arr</span><span class="p" style="box-sizing: border-box;">[</span><span class="nv" style="box-sizing: border-box; color: teal;">$k</span><span class="p" style="box-sizing: border-box;">][</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"url"</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nv" style="box-sizing: border-box; color: teal;">$v</span><span class="p" style="box-sizing: border-box;">[</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"link"</span><span class="p" style="box-sizing: border-box;">];</span>
<span class="nv" style="box-sizing: border-box; color: teal;">$insta_arr</span><span class="p" style="box-sizing: border-box;">[</span><span class="nv" style="box-sizing: border-box; color: teal;">$k</span><span class="p" style="box-sizing: border-box;">][</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"img"</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nv" style="box-sizing: border-box; color: teal;">$v</span><span class="p" style="box-sizing: border-box;">[</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"images"</span><span class="p" style="box-sizing: border-box;">][</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"standard_resolution"</span><span class="p" style="box-sizing: border-box;">][</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"url"</span><span class="p" style="box-sizing: border-box;">];</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">//いったんソートするキーを配列で取り出して、 </span>
<span class="nv" style="box-sizing: border-box; color: teal;">$created_at_arr</span><span class="p" style="box-sizing: border-box;">[</span><span class="nv" style="box-sizing: border-box; color: teal;">$k</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="nv" style="box-sizing: border-box; color: teal;">$v</span><span class="p" style="box-sizing: border-box;">[</span><span class="s2" style="box-sizing: border-box; color: #dd1144;">"created_time"</span><span class="p" style="box-sizing: border-box;">];</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// keyで降順</span>
<span class="nb" style="box-sizing: border-box; color: #0086b3;">array_multisort</span><span class="p" style="box-sizing: border-box;">(</span><span class="nv" style="box-sizing: border-box; color: teal;">$created_at_arr</span> <span class="p" style="box-sizing: border-box;">,</span><span class="nx" style="box-sizing: border-box;">SORT_DESC</span><span class="p" style="box-sizing: border-box;">,</span><span class="nv" style="box-sizing: border-box; color: teal;">$insta_arr</span><span class="p" style="box-sizing: border-box;">);</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">echo</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">json_encode</span><span class="p" style="box-sizing: border-box;">(</span><span class="nv" style="box-sizing: border-box; color: teal;">$insta_arr</span><span class="p" style="box-sizing: border-box;">);</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">exit</span><span class="p" style="box-sizing: border-box;">;</span>
</span></pre>
</div>
</div>
<h3 style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 20px; font-weight: normal; line-height: 1.43; margin: 64px 0px 0.7em; position: relative;">
<span class="fragment" id="js側でソートlodash" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/c046e9070f211a8bb293#js%E5%81%B4%E3%81%A7%E3%82%BD%E3%83%BC%E3%83%88lodash" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>js側でソート(lodash)</h3>
<div class="code-frame" data-lang="javascript" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow: auto; padding: 8px 15px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;"> <span class="nx" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">map</span><span class="p" style="box-sizing: border-box;">(</span><span class="nx" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">sortByOrder</span><span class="p" style="box-sizing: border-box;">(</span><span class="nx" style="box-sizing: border-box;">insta_arr</span><span class="p" style="box-sizing: border-box;">,</span> <span class="p" style="box-sizing: border-box;">[</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'created_at'</span><span class="p" style="box-sizing: border-box;">],</span> <span class="p" style="box-sizing: border-box;">[</span><span class="s1" style="box-sizing: border-box; color: #dd1144;">'desc'</span><span class="p" style="box-sizing: border-box;">]),</span> <span class="nx" style="box-sizing: border-box;">_</span><span class="p" style="box-sizing: border-box;">.</span><span class="nx" style="box-sizing: border-box;">values</span><span class="p" style="box-sizing: border-box;">);</span>
</pre>
</div>
</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px; position: relative;">
<span class="fragment" id="参考" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/you_matz/items/c046e9070f211a8bb293#%E5%8F%82%E8%80%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>参考</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
Issue 37404 - chromium - Chrome reorders keys in the dictionary (object) <a class="autolink" href="http://bit.ly/1Qw0utr" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://bit.ly/1Qw0utr</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
Issue 164 - v8 - Wrong order in Object properties interation - V8 JavaScript Engine<br style="box-sizing: border-box;" /><a class="autolink" href="https://code.google.com/p/v8/issues/detail?id=164" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://code.google.com/p/v8/issues/detail?id=164</a></div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
Google Chromeでjsonオブジェクトを扱う際に、勝手にキーでソートされたよ<br style="box-sizing: border-box;" /><a class="autolink" href="http://log.miraoto.com/2013/02/738/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://log.miraoto.com/2013/02/738/</a></div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-64764322908953720322015-11-16T19:10:00.001+09:002015-11-16T19:10:29.403+09:00SwiftでSafariのリーディングリストに追加<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
Safariのリーディングリストは、後で見たいウェブページをリーディングリストに登録することで、ネット環境が無いオフラインでもiPhone内のストレージにキャッシュされて記事の続きを閲覧できる機能</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
今回はリストに追加する実装を記載</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="はじめに" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/5ace364906d70e9ffd7d#%E3%81%AF%E3%81%98%E3%82%81%E3%81%AB" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>はじめに</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
Build PhasesのLink Binary With Librariesに<br style="box-sizing: border-box;" />iOS7から追加されたSafari Service Frameworkを追加</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="実装" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/5ace364906d70e9ffd7d#%E5%AE%9F%E8%A3%85" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>実装</h2>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow: auto; padding: 8px 15px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;"><span class="k" style="box-sizing: border-box; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">SafariServices</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">title</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"my profile site"</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">url</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSURL</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">string</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"http://manchan.github.io"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// リーディングリストに追加できるかどうかチェック</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">isValid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">SSReadingList</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">supportsURL</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">url</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">list</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">SSReadingList</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">defaultReadingList</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">var</span> <span class="nl" style="box-sizing: border-box;">msg</span><span class="p" style="box-sizing: border-box;">:</span><span class="n" style="box-sizing: border-box;">String</span><span class="o" style="box-sizing: border-box; font-weight: bold;">?</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 追加</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">isValid</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">&&</span> <span class="n" style="box-sizing: border-box;">list</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">addReadingListItemWithURL</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">url</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">previewText</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">error</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">){</span>
<span class="n" style="box-sizing: border-box;">msg</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"追加に成功"</span>
<span class="p" style="box-sizing: border-box;">}</span><span class="k" style="box-sizing: border-box; font-weight: bold;">else</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="n" style="box-sizing: border-box;">msg</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"追加に失敗"</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 確認 </span>
<span class="bp" style="box-sizing: border-box; color: #999999;">UIAlertView</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">title</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"追加test"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">message</span><span class="p" style="box-sizing: border-box;">:</span> <span class="n" style="box-sizing: border-box;">msg</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">delegate</span><span class="p" style="box-sizing: border-box;">:</span> <span class="nb" style="box-sizing: border-box; color: #0086b3;">nil</span><span class="p" style="box-sizing: border-box;">,</span> <span class="nl" style="box-sizing: border-box;">cancelButtonTitle</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"OK"</span><span class="p" style="box-sizing: border-box;">).</span><span class="n" style="box-sizing: border-box;">show</span><span class="p" style="box-sizing: border-box;">()</span>
</pre>
</div>
</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="用例" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/5ace364906d70e9ffd7d#%E7%94%A8%E4%BE%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>用例</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
AppleWatchからニュースの記事見出しだけ見て、親iPhoneのsafariに追加するなどが考えられる実装(Google News, NYTimes)<br style="box-sizing: border-box;" />watchOS1ならopenParentApplicationで送信<br style="box-sizing: border-box;" />watchOS2ならWatch Connectivityで</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="注意" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/5ace364906d70e9ffd7d#%E6%B3%A8%E6%84%8F" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>注意</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
追加済みのURLとかのチェックはできない、また既出のリストも取得、編集、削除できない<br style="box-sizing: border-box;" />読みだすことができれば、いろいろとできそうなので残念。<br style="box-sizing: border-box;" />オフライン閲覧が可能なので、ストレージにキャッシュが貯まるので膨大にある場合、キャッシュを削除する必要がある<br style="box-sizing: border-box;" />iOS9であれば設定から<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">一般 > ストレージとiCloudの使用状況 > ストレージを管理 > Safari</code><br style="box-sizing: border-box;" />のリーディングリストを編集を押して削除</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="参考" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="http://qiita.com/drafts/5ace364906d70e9ffd7d#%E5%8F%82%E8%80%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>参考</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
iOS Developer Library > Safari Services Framework Reference SSReadingList Class Reference<br style="box-sizing: border-box;" /><a class="autolink" href="https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Reference/SSReadingList_Ref/index.html#//apple_ref/occ/cl/SSReadingList" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Reference/SSReadingList_Ref/index.html#//apple_ref/occ/cl/SSReadingList</a></div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-43814813452799982642015-11-13T11:25:00.000+09:002015-11-13T11:25:08.418+09:00RSSで取得したpubDateをNSDateFormatterで変換(Swift)<div style="box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
ロケールが日本語の時に上手く日付を取得できなかったので、残しておく。<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">Wed, 04 Nov 2015 15:02:11 +0000</code><br style="box-sizing: border-box;" />上記のような書式の日付を<br style="box-sizing: border-box;" /><code style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14.4px; padding: 2px 4px;">11月04日(水)</code><br style="box-sizing: border-box;" />に変更します。</div>
<div style="box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
<br /></div>
<div class="code-frame" data-lang="swift" style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 0; margin: 1em 0px;">
<div class="highlight" style="background: rgb(255, 255, 255); box-sizing: border-box;">
<pre style="background-color: #f7f7f7; border-radius: 3px; border: 0px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13px; line-height: 18px; overflow: auto; padding: 8px 15px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;"> <span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// string = "Wed, 04 Nov 2015 15:02:11 +0000"</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">identifier</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSLocale</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">currentLocale</span><span class="p" style="box-sizing: border-box;">().</span><span class="n" style="box-sizing: border-box;">localeIdentifier</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="n" style="box-sizing: border-box;">identifier</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">==</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"ja_JP"</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">dateFormatter</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSDateFormatter</span><span class="p" style="box-sizing: border-box;">()</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 書式が変わらない固定ロケールで一度値を取得</span>
<span class="n" style="box-sizing: border-box;">dateFormatter</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">locale</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSLocale</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">localeIdentifier</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"en_US_POSIX"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">dateFormatter</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">dateFormat</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"EEE, dd MMM yyyy HH:mm:ss ZZZZ"</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">r_date</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">dateFormatter</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">dateFromString</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">string</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="k" style="box-sizing: border-box; font-weight: bold;">let</span> <span class="n" style="box-sizing: border-box;">d</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">r_date</span> <span class="p" style="box-sizing: border-box;">{</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// ロケールを日本語にして曜日を取得</span>
<span class="n" style="box-sizing: border-box;">dateFormatter</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">locale</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="bp" style="box-sizing: border-box; color: #999999;">NSLocale</span><span class="p" style="box-sizing: border-box;">(</span><span class="nl" style="box-sizing: border-box;">localeIdentifier</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"ja_JP"</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">dateFormatter</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">dateFormat</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="s" style="box-sizing: border-box; color: #dd1144;">"MM月dd日(E)"</span>
<span class="n" style="box-sizing: border-box;">tmpEntry</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">addObject</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">dateFormatter</span><span class="p" style="box-sizing: border-box;">.</span><span class="n" style="box-sizing: border-box;">stringFromDate</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">d</span><span class="p" style="box-sizing: border-box;">))</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="p" style="box-sizing: border-box;">}</span>
<span class="c1" style="box-sizing: border-box; color: #999988; font-style: italic;">// 日本語以外</span>
<span class="k" style="box-sizing: border-box; font-weight: bold;">else</span><span class="p" style="box-sizing: border-box;">{</span>
<span class="p" style="box-sizing: border-box;">}</span>
</pre>
</div>
</div>
<div style="box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
localeIdentifierを一度en_US_POSIXにするのがポイント。</div>
<h2 style="border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="参考" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/ccbf337222b2cb98e65b/edit#%E5%8F%82%E8%80%83" style="box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>参考</h2>
<div style="box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
NSDateFormatterの使い方まとめ<br style="box-sizing: border-box;" /><a class="autolink" href="http://qiita.com/gonsee/items/d3fb641914d2ca45e858" style="box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://qiita.com/gonsee/items/d3fb641914d2ca45e858</a></div>
<div style="box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
Swiftで現在日時を取得し、独自のフォーマットで出力する方法<br style="box-sizing: border-box;" /><a class="autolink" href="http://qiita.com/cotrpepe/items/261833c465af5d70f867" style="box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">http://qiita.com/cotrpepe/items/261833c465af5d70f867</a></div>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.comtag:blogger.com,1999:blog-5194113662273041185.post-12377741269291387312015-10-18T21:26:00.000+09:002015-10-18T21:26:19.430+09:00アイディアの出し方<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
アイディアの出し方</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
Webサービス、アプリ企画に関わらず、どんなものに対しても。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="前提条件" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/eedfaf10eaf828566eb9#%E5%89%8D%E6%8F%90%E6%9D%A1%E4%BB%B6" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>前提条件</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
以下のような習慣だとでやすいと感じる。<br style="box-sizing: border-box;" />リラックスした状態、十分な睡眠と運動(ぼーっとした状態の方がでやすい)を定期的に作る。忙しくさせすぎない。夜寝る前はでやすい。<br style="box-sizing: border-box;" />思いついたらすぐにメモを取ること。忘れるから。その方が深く腑に落ちるから。<br style="box-sizing: border-box;" />違和感を大切に。テーマは以下。<br style="box-sizing: border-box;" />「賛成する人がほとんどいない、大切な真実はなんだろう? by Peter Thiel」<br style="box-sizing: border-box;" />人の心を動かすのは何かを徹底的に考え抜く。魔法のようなツールはなくて、徹底的に考えぬく。<br style="box-sizing: border-box;" />マーケティングリサーチに頼ったりは絶対にしない。それだったら誰でもできる、アンケートや調査は作ったあとでいい。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="思考のパターンとして有効だと思うもの" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/eedfaf10eaf828566eb9#%E6%80%9D%E8%80%83%E3%81%AE%E3%83%91%E3%82%BF%E3%83%BC%E3%83%B3%E3%81%A8%E3%81%97%E3%81%A6%E6%9C%89%E5%8A%B9%E3%81%A0%E3%81%A8%E6%80%9D%E3%81%86%E3%82%82%E3%81%AE" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>思考のパターンとして有効だと思うもの</h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box; list-style-type: disc;">問題に対して他の人とは違う捉え方をする</li>
<li style="box-sizing: border-box; list-style-type: disc;">他の人がこわくてできないようなリスクを取る</li>
<li style="box-sizing: border-box; list-style-type: disc;">大勢に立ち向かい、自分の信念も守る</li>
<li style="box-sizing: border-box; list-style-type: disc;">他の人が屈してしまった障害や課題を乗り越える方法を探す(規制の変革をとらえる。etc(遠隔医療、派遣法改正、旅館業法))</li>
<li style="box-sizing: border-box; list-style-type: disc;">長らく寡占化されている市場、もしくはフラグメントな市場を調査</li>
<li style="box-sizing: border-box; list-style-type: disc;">行動を変えるテクノロジー(スマホの登場、将来はVRデバイスや小型投影デバイスなど)</li>
</ul>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="方法" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/eedfaf10eaf828566eb9#%E6%96%B9%E6%B3%95" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>方法</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
大量の情報を頭に詰め込む(情報ソースは人づて、本、映画、流行っているもの(なぜ流行しているか?まで考えて)、Webなど、ありとあらゆる人、事、物すべて)<br style="box-sizing: border-box;" />人の本質的な欲求を知るために、歴史的に続いてきた事象を調べてみること<br style="box-sizing: border-box;" />現状の問題や課題など調査、お客さんが困っていることなどヒアリングすることからはじめる。</div>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; margin-top: 1.6em; word-wrap: break-word;">
その後、<br style="box-sizing: border-box;" />→アイディアを寝かす、睡眠後 →ひらめく<br style="box-sizing: border-box;" />→運動する、歩く、走るなど →ひらめく<br style="box-sizing: border-box;" />→人に話す →ひらめく<br style="box-sizing: border-box;" />→Action →Generate</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="ひらめいた後" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/eedfaf10eaf828566eb9#%E3%81%B2%E3%82%89%E3%82%81%E3%81%84%E3%81%9F%E5%BE%8C" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>ひらめいた後</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
論理検証。ロジックを詰める。<br style="box-sizing: border-box;" />後付でよいので、なぜそれがおもしろいのか?を論理付けする。<br style="box-sizing: border-box;" />似たようなサービスがすでにあっても、表現、手法、媒体を変えてアウトプットする。</div>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="なぜそれが必要なのか" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/eedfaf10eaf828566eb9#%E3%81%AA%E3%81%9C%E3%81%9D%E3%82%8C%E3%81%8C%E5%BF%85%E8%A6%81%E3%81%AA%E3%81%AE%E3%81%8B" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>なぜそれが必要なのか</h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box; list-style-type: disc;">なぜそれを作ったのか、他の人はなぜそれが必要なのか</li>
<li style="box-sizing: border-box; list-style-type: disc;">この問いになんとなくおもしろいでは、ダメで、明確に答えられるように</li>
<li style="box-sizing: border-box; list-style-type: disc;">コンセプト(一言で)、デザイン(統一感、導線)、哲学(何を実現するか、何を根本的に解決したいか)、名前(シンプルでわかりやすい、shareされやすい)</li>
</ul>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="最後に実行" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/eedfaf10eaf828566eb9#%E6%9C%80%E5%BE%8C%E3%81%AB%E5%AE%9F%E8%A1%8C" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>最後に実行</h2>
<div style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.875; word-wrap: break-word;">
アイディアに価値はない、実行がすべて。</div>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 1em; padding-left: 1.5em;">
<li style="box-sizing: border-box; list-style-type: disc;">おもしろい一発屋サービスを出すには、アイディアの数をだしまくる。批判はなし</li>
<li style="box-sizing: border-box; list-style-type: disc;">長く愛されるものを生み出すなら、楽しさだけを追い求めると一発屋になっちゃう。ゆくゆく社会インフラになるサービスは奇をてらった発想じゃ生まれない。 なので人間の普遍的な欲求とはなにかを考えるために、歴史的に続いてきた事象を調べてみる。</li>
<li style="box-sizing: border-box; list-style-type: disc;"><div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
想像のつかないものを考えるのは楽しいが、誰かにとって必要とされるものを作るのも大切なこと。そこから何か生まれるものもある。</div>
</li>
<li style="box-sizing: border-box; list-style-type: disc;"><div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
不確実性の高いアイディアは賛同が得られにくい(合意コストが高い)ので、<br style="box-sizing: border-box;" />多数決とかで決めない。そういうのは勝手に個人でやる。</div>
</li>
<li style="box-sizing: border-box; list-style-type: disc;"><div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
多数決でやるなら、社会通念のバイアスとその破壊方法の合意にHowの部分で多数の力を借りる。</div>
</li>
</ul>
<h2 style="background-color: white; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 22px; font-weight: normal; line-height: 1.225; margin: 64px 0px 12px; padding-bottom: 8px;">
<span class="fragment" id="参考" style="box-sizing: border-box; display: block; position: relative; top: -10px;"></span><a href="https://qiita.com/drafts/eedfaf10eaf828566eb9#%E5%8F%82%E8%80%83" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;"></a>参考</h2>
<ul style="background-color: white; box-sizing: border-box; color: #4a4a4a; font-family: 'Helvetica Neue', Helvetica, 'ヒラギノ角ゴ ProN W3', 'Hiragino Kaku Gothic ProN', メイリオ, Meiryo, sans-serif; font-size: 16px; line-height: 1.7; margin-bottom: 1em; margin-top: 0px; padding-left: 1.5em;">
<li style="box-sizing: border-box; list-style-type: disc;"><div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
<a href="http://wired.jp/2015/03/06/peter-thiel-startup/" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">ピーター・ティールが、日本の学生に語った10のこと - wired</a></div>
</li>
<li style="box-sizing: border-box; list-style-type: disc;"><div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
<a href="http://www.1101.com/peter_thiel/2015-04-27.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">賛成する人がいない、大切な真実とはなにか。ピーター・ティールと糸井重里の対談 - ほぼ日刊イトイ新聞</a></div>
</li>
<li style="box-sizing: border-box; list-style-type: disc;"><div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
<a href="http://engineer.typemag.jp/article/yasuoxhashi2" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">ひがやすを×橋口恭子が”LINEを超えるアプリ”を誌上ブレスト「長く愛されるサービスを作るプロセスとは?」</a></div>
</li>
<li style="box-sizing: border-box; list-style-type: disc;"><div style="box-sizing: border-box; font-size: 1em; line-height: 1.875; word-wrap: break-word;">
<a href="http://www.lifehacker.jp/2014/04/140425creative_thinking_habit.html" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration: none; word-break: break-all; word-wrap: break-word;">創造性は才能というよりむしろ習慣。今から身につけることもできます - lifehacker</a></div>
</li>
</ul>
you_matzhttp://www.blogger.com/profile/07302544665454080920noreply@blogger.com