tag:blogger.com,1999:blog-91579588194171436152023-11-16T07:49:49.532-08:00阿斌的筆記Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.comBlogger125125tag:blogger.com,1999:blog-9157958819417143615.post-20304235097249766842022-01-06T19:37:00.004-08:002022-01-06T19:37:41.422-08:00[Xcode] Xcode 13 顯示副檔名<p>Xcode -> Preferences -> General -> File Extensions -> Show all</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhZ05wh0EXVoqYGQsUSfXez3W-i5IBYIgguB-9-W7Dl_TEPzHDFwD4Bkazc6n6QfVeEaEnRsb51gDrm6JOLFvhcYvXn_PIn2cLzrjL1so_HiSSrgDfOr2Bk1VGwrEb97cBuQp8bQU52C0-HK2tdwk3IfoFF4y9h71wuOfE_BgcNU8f9Fvym4wvtEH02pg=s366" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="366" data-original-width="331" height="400" src="https://blogger.googleusercontent.com/img/a/AVvXsEhZ05wh0EXVoqYGQsUSfXez3W-i5IBYIgguB-9-W7Dl_TEPzHDFwD4Bkazc6n6QfVeEaEnRsb51gDrm6JOLFvhcYvXn_PIn2cLzrjL1so_HiSSrgDfOr2Bk1VGwrEb97cBuQp8bQU52C0-HK2tdwk3IfoFF4y9h71wuOfE_BgcNU8f9Fvym4wvtEH02pg=w361-h400" width="361" /></a></div><p><br /></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjH6gtPtDoKp3i5gq6jroTzKKz2Xh_l0Zl83sWlGjq9mU53vrU80E17T2qDlPKxtHx-V2bHCNyeOlz5BjDvgnmn5GGl14kPF92Ne6d1qvDGF5KREkZVLrApHBFLVtvwKxajsllkxj_9rfnPs9F9NzEEenioG1yfilNxSPKtJ07BquwTP89ytBu9bfRfIg=s1658" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1012" data-original-width="1658" height="390" src="https://blogger.googleusercontent.com/img/a/AVvXsEjH6gtPtDoKp3i5gq6jroTzKKz2Xh_l0Zl83sWlGjq9mU53vrU80E17T2qDlPKxtHx-V2bHCNyeOlz5BjDvgnmn5GGl14kPF92Ne6d1qvDGF5KREkZVLrApHBFLVtvwKxajsllkxj_9rfnPs9F9NzEEenioG1yfilNxSPKtJ07BquwTP89ytBu9bfRfIg=w640-h390" width="640" /></a></div><br />Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-52177189354709994892021-07-28T23:24:00.005-07:002021-07-29T18:24:06.012-07:00[Android] BottomNavigationView - 底部導航欄的基本用法<p>BottomNavigationView是一種十分流行的UI設計介面,透過底部導航欄提供使用者切換頁面。</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIRQPL4bOby658iAmFrOm805-MkykbmHjqF-nMPnndNlkRRP7z_dW7xxN0j03TR7lO_g1A0rNKikuRVeFAJ7bMtSDWPvzy0nPAyWr3krQDwu4-wqdbflDTZJB5s_H3ol77YkTezo52txDu/s1920/Screenshot_1627535685.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1920" data-original-width="1080" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIRQPL4bOby658iAmFrOm805-MkykbmHjqF-nMPnndNlkRRP7z_dW7xxN0j03TR7lO_g1A0rNKikuRVeFAJ7bMtSDWPvzy0nPAyWr3krQDwu4-wqdbflDTZJB5s_H3ol77YkTezo52txDu/w360-h640/Screenshot_1627535685.png" width="360" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">這邊就來稍微說明一下該如何使用,這邊我們使用新的Activity頁面來當範例,這樣比較能夠了解需要哪些步驟。</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">首先我們於要展示的Activity中,加入BottomNavigationView,並且設置對應的Constraint,讓它位於畫面的底部,別忘了設置對應的id,這邊我們命名為nav_view。</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGJ6CIQhdINxcArH8I5x7GVbtNFGuNqdVmaRAPfGXu3UoWY6I_rGVrWAIz7TRoHxwstPyIwcrzYYZBnIFGsSrbsgkSViWnpWPHl_pQFl2n18lEsGWtR_dX2x8SvHS9ytwMdla9yQ-6Y51m/s332/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.22.53.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="304" data-original-width="332" height="293" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGJ6CIQhdINxcArH8I5x7GVbtNFGuNqdVmaRAPfGXu3UoWY6I_rGVrWAIz7TRoHxwstPyIwcrzYYZBnIFGsSrbsgkSViWnpWPHl_pQFl2n18lEsGWtR_dX2x8SvHS9ytwMdla9yQ-6Y51m/w320-h293/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.22.53.png" width="320" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0xABFkXG20GOT_7gLrb2qD_t3IDDC2VNAn_44EpBmoQtmr1iNjFp02jaRr8qJbOGkOsyyvjUc_QSyByVgcOyRsPMb_0nNeb0A-e5JkPeyYW4QI00gDztZmFHnUy03Q9QsqTkdmtMqywWF/s980/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.23.10.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="616" data-original-width="980" height="402" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0xABFkXG20GOT_7gLrb2qD_t3IDDC2VNAn_44EpBmoQtmr1iNjFp02jaRr8qJbOGkOsyyvjUc_QSyByVgcOyRsPMb_0nNeb0A-e5JkPeyYW4QI00gDztZmFHnUy03Q9QsqTkdmtMqywWF/w640-h402/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.23.10.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">接著,你需要將每個選項對應的圖片加入到你的專案之中,這邊你可以自由選擇你想要的圖片,如果不知道該去哪邊下載圖片,可以到以下的網站進行下載。<br /></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><a href="https://www.flaticon.com/">https://www.flaticon.com/</a></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">這邊我們加入首頁、我的最愛與設定三個選項的圖片。</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidspUqPVGQbCI4yhoXo_GD1Hxwi8dbUw14qp5cgBZc7nqkhmi34Plv45sXELkLmHLm0NTGqmg8xyXaKJmRH7vpTYCwHCcY5rBlS0vZ6twGfIdU6MUnBrolz001d-1LlNVrAfS5YucreSLn/s634/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.26.17.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="359" data-original-width="634" height="362" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidspUqPVGQbCI4yhoXo_GD1Hxwi8dbUw14qp5cgBZc7nqkhmi34Plv45sXELkLmHLm0NTGqmg8xyXaKJmRH7vpTYCwHCcY5rBlS0vZ6twGfIdU6MUnBrolz001d-1LlNVrAfS5YucreSLn/w640-h362/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.26.17.png" 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/AVvXsEimaNz6U2UN9s8D1lryao7SHcxgYXVKDPrGN6uDcFpmsckOlyLAGC2VEGo3iP49i9KXRHY7PDpotYJF2nPRyIJP-5vfRCo96lvUSUVPaIGehwL3RQKLaI_IsFkPDUyDTyFb32bKWdZApAAa/s275/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.27.26.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="144" data-original-width="275" height="209" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimaNz6U2UN9s8D1lryao7SHcxgYXVKDPrGN6uDcFpmsckOlyLAGC2VEGo3iP49i9KXRHY7PDpotYJF2nPRyIJP-5vfRCo96lvUSUVPaIGehwL3RQKLaI_IsFkPDUyDTyFb32bKWdZApAAa/w400-h209/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.27.26.png" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">接下來,我們可以新增這三個頁面對應的Fragment。</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSkLHY28odKA52xDzTTZnDDwA_ozdRBf1hg6z2kyZrAlInEaN9BGQr_qs1t6r1iSvzkPLadMnJmigOXWpv_77l3WMH8BKGev6SIXNLU3DAXHB9nWY2-3kbMV3ldz8xycCBEM6yioEBmkYg/s238/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.30.55.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="145" data-original-width="238" height="195" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSkLHY28odKA52xDzTTZnDDwA_ozdRBf1hg6z2kyZrAlInEaN9BGQr_qs1t6r1iSvzkPLadMnJmigOXWpv_77l3WMH8BKGev6SIXNLU3DAXHB9nWY2-3kbMV3ldz8xycCBEM6yioEBmkYg/w320-h195/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.30.55.png" width="320" /></a></div><br /><div class="separator" style="clear: both; text-align: left;">你可以為它們設置不同的背景顏色,或者增加一些元件,可以區分不同的頁面,這邊我使用不同的顏色進行區分。</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">HomeFragment -> 藍色</div><div class="separator" style="clear: both; text-align: left;">FavouriteFragment -> 紅色</div><div class="separator" style="clear: both; text-align: left;">SettingFragment -> 綠色</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">下一步,我們新增一個Navigation,用於管理這三個頁面之用,將焦點移到res上,選擇新增資源:</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXLfNp8ujwDIp6XK_nWbW3qUvZ0-ROtNMsT48q1Ej7U4YTaMgFZ5hY5WuYsOrTuU78wMZzC5bfRJglq9z3e9tXkY-A3LDAxrhHGhZDR_1tN3kSOjv2oUCLSDL2qMuG3CohhOR9-6bKMSTs/s773/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.35.11.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="349" data-original-width="773" height="288" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXLfNp8ujwDIp6XK_nWbW3qUvZ0-ROtNMsT48q1Ej7U4YTaMgFZ5hY5WuYsOrTuU78wMZzC5bfRJglq9z3e9tXkY-A3LDAxrhHGhZDR_1tN3kSOjv2oUCLSDL2qMuG3CohhOR9-6bKMSTs/w640-h288/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.35.11.png" width="640" /></a></div><br /><div class="separator" style="clear: both; text-align: left;">將Resource type改成Navigation,並且將檔案名稱命名為bottom_nav_navigation。</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNB2L1svn6mYb-9MLPgeuFwix4cMSJeXfb9_C687O_SvpKY19wx8i0Lup85KizQec68AIuIY5h8dgWB-nGPMv3kk6WHN8_uM0wFcpOuqm6fXIGARbXozY6_NA0K4UtzUgkIuUwFf2f8Qme/s936/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.37.45.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="594" data-original-width="936" height="406" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNB2L1svn6mYb-9MLPgeuFwix4cMSJeXfb9_C687O_SvpKY19wx8i0Lup85KizQec68AIuIY5h8dgWB-nGPMv3kk6WHN8_uM0wFcpOuqm6fXIGARbXozY6_NA0K4UtzUgkIuUwFf2f8Qme/w640-h406/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.37.45.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: left;">接下來開啟剛才新增的bottom_nav_navigation.xml,點擊新增,把我們要展示的Fragment新增到這個檔案之中。</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_-iV3AZBIcwE0fB5uGQL5I4Vt4tGoQbEE2GLPrLQNhmeh7cWtaGsWSglpamgFMFfZNUaY5wdj_53Apa-6h_AnCpA9sRwydoAvA_DYzDBCbqDfONYpjPEMH4_oBlNe8eGpcrfYf6U02NbI/s810/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.38.42.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="581" data-original-width="810" height="460" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_-iV3AZBIcwE0fB5uGQL5I4Vt4tGoQbEE2GLPrLQNhmeh7cWtaGsWSglpamgFMFfZNUaY5wdj_53Apa-6h_AnCpA9sRwydoAvA_DYzDBCbqDfONYpjPEMH4_oBlNe8eGpcrfYf6U02NbI/w640-h460/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.38.42.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">這邊別忘了為這三個Fragment定義id,點選後將目光移到右方,就可以定義你選擇的Fragment</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIwevLKl4aZsS9T3KtW5ruCNSk5BCgV9kX4XLdmKSE4QlUKAf7a0f7dHqJI9EAPlmnrmyZixUnM8r2rxqWH0adLaqkr7jHJKk8ieh_QXyFvUukQd-5KiuDTo9vpIrzP3I6yUcUibfPdSqW/s1049/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.41.59.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="639" data-original-width="1049" height="390" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIwevLKl4aZsS9T3KtW5ruCNSk5BCgV9kX4XLdmKSE4QlUKAf7a0f7dHqJI9EAPlmnrmyZixUnM8r2rxqWH0adLaqkr7jHJKk8ieh_QXyFvUukQd-5KiuDTo9vpIrzP3I6yUcUibfPdSqW/w640-h390/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.41.59.png" width="640" /></a></div><br /><div class="separator" style="clear: both; text-align: left;">這邊我們將這三個Fragment定義成不同的id</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><div class="separator" style="clear: both;">HomeFragment -> navigation_home</div><div class="separator" style="clear: both;">FavouriteFragment -> navigation_favourite</div><div class="separator" style="clear: both;">SettingFragment -> navigation_setting</div></div><div><br /></div>接下來,我們要新增一個menu,用於展示於BottomNavigationView,一樣將焦點移回res,並且新增資源:<div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhwpFiJutJLjo5cM8klvbBBVVqvjv-xtGM1_KTJv-eqmTtfsTSEhvo4gR16eekpDNl62xzUYvzdpfAH5wpWGeqvtd1mA-HAif0SdeX31NHLuIbfAVfHOdGwWcJRVcHWPhsK_j_JF_1xHuf/s738/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.44.41.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="405" data-original-width="738" height="352" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhwpFiJutJLjo5cM8klvbBBVVqvjv-xtGM1_KTJv-eqmTtfsTSEhvo4gR16eekpDNl62xzUYvzdpfAH5wpWGeqvtd1mA-HAif0SdeX31NHLuIbfAVfHOdGwWcJRVcHWPhsK_j_JF_1xHuf/w640-h352/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.44.41.png" width="640" /></a></div><br /><div><div class="separator" style="clear: both;">將Resource type改成Menu,並且將檔案名稱命名為bottom_nav_menu。</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfEtHYEnclm6jZ_oqsgdSU1EK7lkpd2qYL96MdnHI-6EKT23CnFhA00nQEyEZH11IS23xuuJLRVfQsX7y3M3Y2XWfjpUoMqfwZMSEQTQuBwXAVZagXnzR0G8rEuMTC52ceVAqk1HSwb2k2/s936/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.45.05.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="594" data-original-width="936" height="406" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfEtHYEnclm6jZ_oqsgdSU1EK7lkpd2qYL96MdnHI-6EKT23CnFhA00nQEyEZH11IS23xuuJLRVfQsX7y3M3Y2XWfjpUoMqfwZMSEQTQuBwXAVZagXnzR0G8rEuMTC52ceVAqk1HSwb2k2/w640-h406/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.45.05.png" width="640" /></a></div><br /><div class="separator" style="clear: both;">我們開啟剛才新增的bottom_nav_menu.xml,設置對應的menu item,由上方的Palette拖曳menu item到下方的menu之中:</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg3aMnMlDeWNytSK_F3g7K7Qq9TIjjo3UWAr8_tz4p0jAlsNuCisGwnDag_qkIMts0EChgAeqWu13uW8K6ORRNDeLxQgRWPEdMt9a_6TPW_pkMSF2ADPkYVOdnL0TrhXadnO3oUuuWyJI9/s595/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.47.06.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="595" data-original-width="346" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg3aMnMlDeWNytSK_F3g7K7Qq9TIjjo3UWAr8_tz4p0jAlsNuCisGwnDag_qkIMts0EChgAeqWu13uW8K6ORRNDeLxQgRWPEdMt9a_6TPW_pkMSF2ADPkYVOdnL0TrhXadnO3oUuuWyJI9/w233-h400/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.47.06.png" width="233" /></a></div><br /><div class="separator" style="clear: both;">接著你可以於右方設置對應的標題、圖片:</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhptGBq1JZW_IkkDjEYb-UjBH9cua5kY9F-dmIs-UZaRhoKb4npQcJD0SO_svcmDOvTdHLkncyzrcZrOMFtcb3AeX0xYf1w0hyphenhyphenYpkWRvP4iC3lQYck1lfev6_jYjMRMa7mmF9vnSWvCGiiP/s274/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.48.38.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="206" data-original-width="274" height="301" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhptGBq1JZW_IkkDjEYb-UjBH9cua5kY9F-dmIs-UZaRhoKb4npQcJD0SO_svcmDOvTdHLkncyzrcZrOMFtcb3AeX0xYf1w0hyphenhyphenYpkWRvP4iC3lQYck1lfev6_jYjMRMa7mmF9vnSWvCGiiP/w400-h301/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.48.38.png" width="400" /></a></div><br /><div class="separator" style="clear: both;">這邊要特別注意,你還得設定id,而id必須於剛才在bottom_nav_navigation.xml所對應的Fragment id相同,舉例來說,首頁的Fragment id應該是navigation_home,因此首頁menu item的id也必須設置成navigation_home。</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrdepaZfmuC3oMMXk8Gdg8RxZxbwpFYx5DHdf2oWLoBj9svfYZNPGRmSV_82KbWc_o7TvYmVOwu1E1lSsfbfwYzVXru4rjEHLXVnEs16wIIzZw0XcW9uzlwZBeOSsnvSBZUeX75A9a3p9V/s263/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.50.54.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="179" data-original-width="263" height="272" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrdepaZfmuC3oMMXk8Gdg8RxZxbwpFYx5DHdf2oWLoBj9svfYZNPGRmSV_82KbWc_o7TvYmVOwu1E1lSsfbfwYzVXru4rjEHLXVnEs16wIIzZw0XcW9uzlwZBeOSsnvSBZUeX75A9a3p9V/w400-h272/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.50.54.png" width="400" /></a></div><br /><div class="separator" style="clear: both;">其他的部分也是一樣,我們將另外兩個頁面的menu item也設置完成。</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2yZiXkfAVFU0-yIBC3rV8e5ZckKQOZiamdBEBToRJrwnbyKBYA0qppt-hqMz2NUiddhHiAkoN5-TIb8IgzVhmRFSriCh4fCmq6NJL7zy76NRdTlsHoN5saLALsgQ01Da83OZLHvFKlbCk/s1053/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.53.05.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="794" data-original-width="1053" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2yZiXkfAVFU0-yIBC3rV8e5ZckKQOZiamdBEBToRJrwnbyKBYA0qppt-hqMz2NUiddhHiAkoN5-TIb8IgzVhmRFSriCh4fCmq6NJL7zy76NRdTlsHoN5saLALsgQ01Da83OZLHvFKlbCk/w640-h482/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.53.05.png" width="640" /></a></div><br /><div class="separator" style="clear: both;">接著,我們回到要展示的activity的layout,我們將一開始加入的BottomNavigationView設置對應的menu為我們建立的bottom_nav_menu。</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;">選擇BottomNavigationView後,將目光移到右方,選擇menu進行設定。</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9LVA3ZscUSP9ImYdHTxSYMJY2UXvEusV6xxcljAPUiDrv6vjd-a7v1ClwhxVdE7B5SDVX34jctK5BfsiAR8ygI1gBlrvDKqjewAiEo3BLUFYCsK0mgP5ADgUtCWKivXwv_MftNEzKn7pP/s292/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.56.05.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="292" height="343" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9LVA3ZscUSP9ImYdHTxSYMJY2UXvEusV6xxcljAPUiDrv6vjd-a7v1ClwhxVdE7B5SDVX34jctK5BfsiAR8ygI1gBlrvDKqjewAiEo3BLUFYCsK0mgP5ADgUtCWKivXwv_MftNEzKn7pP/w400-h343/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.56.05.png" width="400" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVzBAYDBRgsg1Jhg7M7OkD__iooVMeQks4vjeHLLA5hpqwqzJwiC9os2CRH-ZcXcLt__6uKbn5oGVN85Ls41En2-MPKf-dbGBLo_udZhHJ2p8LWbqW8PQ441XZuGW28bhM8qXdsl0BBRo3/s986/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.56.57.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="814" data-original-width="986" height="528" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVzBAYDBRgsg1Jhg7M7OkD__iooVMeQks4vjeHLLA5hpqwqzJwiC9os2CRH-ZcXcLt__6uKbn5oGVN85Ls41En2-MPKf-dbGBLo_udZhHJ2p8LWbqW8PQ441XZuGW28bhM8qXdsl0BBRo3/w640-h528/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.56.57.png" width="640" /></a></div>接著,你應該可以看到BottomNavigationView擁有對應的menu item了。</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvKFx3xnJedWOjrfJwLv8WlxGaZT7ui-58MWTV7JcyI1AfSMiRXQiVUA9_7VBsxNuKahIzglYo66IPiW_ECc3gtact7KE9u-AuD4Qa98Uh7UfFP4rETwTHyKwcsUdYuVJtI8Ibwjw3cyZE/s925/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.58.32.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="325" data-original-width="925" height="224" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvKFx3xnJedWOjrfJwLv8WlxGaZT7ui-58MWTV7JcyI1AfSMiRXQiVUA9_7VBsxNuKahIzglYo66IPiW_ECc3gtact7KE9u-AuD4Qa98Uh7UfFP4rETwTHyKwcsUdYuVJtI8Ibwjw3cyZE/w640-h224/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25881.58.32.png" width="640" /></a></div><br /><div>接下來,我們要增加一個NavHostFragment到Activity之中,用於展示不同的Fragment。</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOH1lQDD_mh3_-w0PzK0uBDkbJIQIodye2Kpmyqehrl-m_eqO84boYRP_6wXnUPjXdxY85Hd-MoChpQtQ7yqFiVj8Ky-f8FvPSLDCvosFBKgmm9EtJr2Ru8bXIgGwXqYPKxj8EnjBEr2wv/s395/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25882.00.38.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="395" data-original-width="335" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOH1lQDD_mh3_-w0PzK0uBDkbJIQIodye2Kpmyqehrl-m_eqO84boYRP_6wXnUPjXdxY85Hd-MoChpQtQ7yqFiVj8Ky-f8FvPSLDCvosFBKgmm9EtJr2Ru8bXIgGwXqYPKxj8EnjBEr2wv/w339-h400/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25882.00.38.png" width="339" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">這邊選擇剛才所建立的bottom_nav_navigation</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXn_qlBZKJV77rpMTv8Ib47XtNS_f2JRzvK2V60oEL6jSaaQ2nYh5NR0MY3k98GDdLLh1YUWrz6vyeFzYKcp3IFrx5Te40eEGivWbsFYtqMFlU_H7wcE1mMRUE8O40tso25Tg2VDOQsYBf/s986/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25882.00.44.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="814" data-original-width="986" height="528" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXn_qlBZKJV77rpMTv8Ib47XtNS_f2JRzvK2V60oEL6jSaaQ2nYh5NR0MY3k98GDdLLh1YUWrz6vyeFzYKcp3IFrx5Te40eEGivWbsFYtqMFlU_H7wcE1mMRUE8O40tso25Tg2VDOQsYBf/w640-h528/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25882.00.44.png" width="640" /></a></div>加入後,設置簡單的Constraint,將畫面填滿於螢幕,並且設置id,這邊我們將它命名為nav_host_fragment_activity_main。<div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv1-SdE64JYc_nVw1LxXb9UHg4wCg0sS-8KsNaI4W9ntBcktW_hIe4IM8SSkpoRHmH_aGFrpxKSmXH7TVkC0UttYHgzfThY2zxekRfM6jVrPhCA8sYCUWRMbkAPHMI8a6i-qpc_07dzv9J/s1156/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25882.03.41.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="787" data-original-width="1156" height="436" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv1-SdE64JYc_nVw1LxXb9UHg4wCg0sS-8KsNaI4W9ntBcktW_hIe4IM8SSkpoRHmH_aGFrpxKSmXH7TVkC0UttYHgzfThY2zxekRfM6jVrPhCA8sYCUWRMbkAPHMI8a6i-qpc_07dzv9J/w640-h436/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25882.03.41.png" width="640" /></a></div><br /><div>這邊我們採用ViewBinding的形式來管理,於gradle增加以下的語法</div><div><br /></div><div><br /></div><div><p class="p1" style="font-family: "Helvetica Neue"; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">android {</p><p class="p1" style="font-family: "Helvetica Neue"; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span>...</p><p class="p1" style="font-family: "Helvetica Neue"; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span>buildFeatures {</p><p class="p1" style="font-family: "Helvetica Neue"; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span>viewBinding true</p><p class="p1" style="font-family: "Helvetica Neue"; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><span class="Apple-converted-space"> </span>}</p><p class="p1" style="font-family: "Helvetica Neue"; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;">}</p><p class="p1" style="font-family: "Helvetica Neue"; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><br /></p><p class="p1" style="font-family: "Helvetica Neue"; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;"><br /></p></div><div><div class="separator" style="clear: both;">並且將專案clear與build,接著將Activity的程式碼修改成ViewBinding的模式</div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0KzOpSq3AE-6t0Z_w57vAeAGJ7IRh3KhVrcHe66D9UsTcREav79YtnxpDvvuvaOTPBUyxHBUIDuf80IEV5Ymn3f-bOSIuatywrPRZrEgsMR5IvUuji7fmFAFAjK1n7kfbTOuZgUTnga1c/s534/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25882.16.52.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="331" data-original-width="534" height="396" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0KzOpSq3AE-6t0Z_w57vAeAGJ7IRh3KhVrcHe66D9UsTcREav79YtnxpDvvuvaOTPBUyxHBUIDuf80IEV5Ymn3f-bOSIuatywrPRZrEgsMR5IvUuji7fmFAFAjK1n7kfbTOuZgUTnga1c/w640-h396/%25E6%2588%25AA%25E5%259C%2596+2021-07-29+%25E4%25B8%258B%25E5%258D%25882.16.52.png" width="640" /></a></div><div><br /></div>接下來,我們要將BottomNavigationView與navController進行連動,我們透過以下的程式碼取出BottomNavigationView與navController,最後進行設置,這麼一來使用者點選menu,上方的Fragment就會進行切換。</div><div><br /></div><div><script src="https://gist.github.com/Aiur3908/5531043daf7e96352b8e2bcf244f0f33.js"></script><div class="separator" style="clear: both; text-align: left;">這麼一來就算是大功告成了,你可以試著執行看看。</div><br /><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><br /></div><br /></div>Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-55905328226714261642021-07-27T23:14:00.003-07:002021-07-27T23:14:53.082-07:00[Android] Android 12+ 需要設置android:exported屬性才能執行<p>開啟新專案後,執行時遇到了以下的錯誤內容</p><p>Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.</p><div>查了下問題,原因是,如果你的App是以Android 12以上為目標的話,就必續設置該屬性:</div><div><span style="color: var(--devsite-code-color);"><br /></span></div><div><span style="color: var(--devsite-code-color);">android:exported</span></div><div>該屬性為,你的Activity是否可以由其他App開啟,可設置true or false,設置完成後就可以正常運作了。</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7Z7LJkYK-tsYde0DU6WydfBAUud3J5LH_iH8j6AAJE3XsDLUgBWLRCXRaNXxkPRo_5DNhs89nG5mnPy0mIP3iWKFDW4ywAAz9qGySwapQhyfcQkROR7h71ZDres1nOCLYa-bTE8FhAQ2F/s1430/%25E6%2588%25AA%25E5%259C%2596+2021-07-28+%25E4%25B8%258B%25E5%258D%25882.14.24.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1082" data-original-width="1430" height="484" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7Z7LJkYK-tsYde0DU6WydfBAUud3J5LH_iH8j6AAJE3XsDLUgBWLRCXRaNXxkPRo_5DNhs89nG5mnPy0mIP3iWKFDW4ywAAz9qGySwapQhyfcQkROR7h71ZDres1nOCLYa-bTE8FhAQ2F/w640-h484/%25E6%2588%25AA%25E5%259C%2596+2021-07-28+%25E4%25B8%258B%25E5%258D%25882.14.24.png" width="640" /></a></div><br /><div><br /></div>Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-80917394719226180532021-07-27T22:40:00.004-07:002021-07-27T22:40:40.375-07:00[Android Studio] 處理 Invalid Gradle JDK configuration found的問題<p>有時候會需要從別處取得專案,這時候Android Studio可能會產生以下的錯誤</p><p>Invalid Gradle JDK configuration found.</p><p>這時候你只需要關閉專案,並且開啟專案資料夾,將以下的檔案刪除:</p><p>.gradle</p><p>.idea</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNSmcNJSWLlxbxyX3CpxDpL7olFSAphdYIe9imRb39YCoWOsk3pdQrurHHswUQF6Ke3dBD3OOAe2E6FE4BH7GevO9LZSuEYUsrI6pr6QSY4MqOEE9R2ZgLbq4zZ7PXwsUUrPZZR4vmJewg/s1010/%25E6%2588%25AA%25E5%259C%2596+2021-07-28+%25E4%25B8%258B%25E5%258D%25881.37.36.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="430" data-original-width="1010" height="272" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNSmcNJSWLlxbxyX3CpxDpL7olFSAphdYIe9imRb39YCoWOsk3pdQrurHHswUQF6Ke3dBD3OOAe2E6FE4BH7GevO9LZSuEYUsrI6pr6QSY4MqOEE9R2ZgLbq4zZ7PXwsUUrPZZR4vmJewg/w640-h272/%25E6%2588%25AA%25E5%259C%2596+2021-07-28+%25E4%25B8%258B%25E5%258D%25881.37.36.png" width="640" /></a></div><p>這兩個檔案必須由你自己的電腦產生,因此你要刪除它們,接著重新開啟專案,</p><p>讓Android Studio自動產生對應的檔案,應該就可以處理此問題了。</p><p>參考資料</p><p><a href="https://stackoverflow.com/questions/32654016/invalid-jdk-configuration-found-while-importing-a-project-via-gradle" target="_blank">Invalid JDK configuration found, while importing a project via Gradle</a></p>Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-81624652717032609802020-08-03T19:25:00.002-07:002020-08-03T19:46:39.107-07:00[iOS] 重新簽名ipa (Resign ipa)有些時候會需要重新簽名ipa,打包完ipa後又更改裡面的資訊,如果沒有重新簽名就沒辦法安裝。<div><br /></div><div><font color="#ff0000"><b>Application</b></font>請自行改成你的名稱</div><div><br /></div><div>1. 解壓縮ipa</div><div><!--?xml version="1.0" encoding="UTF-8"?-->
<div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;">unzip Application.ipa </div></div><div><br /></div><div>2.移除舊有的簽名</div><div><br /></div><div><div style="-en-codeblock: true; background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;">rm -rf "Payload/Application.app/_CodeSignature/" </div></div><div><br /></div><div>3.替換mobileprovision</div><div><br /></div><div><!--?xml version="1.0" encoding="UTF-8"?-->
<div style="-en-clipboard: true; -en-codeblock: true; background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;">cp "NewMobileprovision.mobileprovision" "Payload/Application.ipa/embedded.mobileprovision" </div></div><div><br /></div><div><b><font color="#ff0000">NewMobileprovision .mobileprovision</font></b>這個檔案必須從蘋果開發者網站下載</div><div><a href="https://developer.apple.com/">https://developer.apple.com/</a></div><div><br /></div><div>1.選擇Profiles</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix-TsXQMcQKB4Q09zdU53UmRQWnDLDZVzymb-CQEe83euSG870poqNiMo1q-v2hq86GfmeEOkBbrxZ_MdUWV73T2wl_0PsSY5zXYp3S7kZ4Vln7HZUkVAdWQExcOLFFM22BWb3z3LUFgkS/s2570/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.06.58.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="812" data-original-width="2570" height="202" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix-TsXQMcQKB4Q09zdU53UmRQWnDLDZVzymb-CQEe83euSG870poqNiMo1q-v2hq86GfmeEOkBbrxZ_MdUWV73T2wl_0PsSY5zXYp3S7kZ4Vln7HZUkVAdWQExcOLFFM22BWb3z3LUFgkS/w640-h202/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.06.58.png" width="640" /></a></div><div>2.選擇Ad Hoc</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpxhPJKYxGxEct_W0mSLK1wRIBFRrDSviO6ieWTe51NkRZD_sRIUyVMmFXOoZriZPp1NEmeZlzLtvw-93FZEnyqr1s329sQQj5wqtTwU2MlYGvGoLdRwfGaH1a6XTjpbpHXARD-ah2fyLx/s2048/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.07.05.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1419" data-original-width="2048" height="443" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpxhPJKYxGxEct_W0mSLK1wRIBFRrDSviO6ieWTe51NkRZD_sRIUyVMmFXOoZriZPp1NEmeZlzLtvw-93FZEnyqr1s329sQQj5wqtTwU2MlYGvGoLdRwfGaH1a6XTjpbpHXARD-ah2fyLx/w640-h443/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.07.05.png" width="640" /></a></div><div>3.選擇App ID</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw7KhoyDgSP8prYnGpsOZ6R2Ss1P6YItrZ91T7JLo33C4-a_L7Cqg7uroPcZdXBvr-tEK9RtuyUbBU7tMFRWTFzbUuLNmTCNOZck8qhDxBDxrB1PC17RcAHGwFCIrIb5l1knqsVf3TzAdR/s2374/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.07.32.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="534" data-original-width="2374" height="144" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw7KhoyDgSP8prYnGpsOZ6R2Ss1P6YItrZ91T7JLo33C4-a_L7Cqg7uroPcZdXBvr-tEK9RtuyUbBU7tMFRWTFzbUuLNmTCNOZck8qhDxBDxrB1PC17RcAHGwFCIrIb5l1knqsVf3TzAdR/w640-h144/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.07.32.png" width="640" /></a></div><div>4.選擇憑證</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-BCTk55xiwgBY83HI2guMbSfR2x7-oyrAC3Yy7PaPGDUKWq1sDdXSUPqIw4WKFFyNBL5PHd7jCo0ahEmr37Ao0g3pSbKt5YawsSExdiLJur0gaw04hfU5rHAQo2x0f0bTEU47gwMh8WFd/s2390/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.07.45.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="460" data-original-width="2390" height="123" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-BCTk55xiwgBY83HI2guMbSfR2x7-oyrAC3Yy7PaPGDUKWq1sDdXSUPqIw4WKFFyNBL5PHd7jCo0ahEmr37Ao0g3pSbKt5YawsSExdiLJur0gaw04hfU5rHAQo2x0f0bTEU47gwMh8WFd/w640-h123/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.07.45.png" width="640" /></a></div><div><br /></div><div><br /></div><div>5.選擇可以安裝此ipa的裝置</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLj11-2I9kaRhUqejiXWjhVRsQW-MJbmSgU9duqSxHztPJHZ9_nNB3dQlpLeYvMZEL2lc64DCoO-gZQ9yC1AbE0xDsUz-hoXg3rEewyOcuS6EGv02yDpygiprQJMKme14rSaW2vxK70cs7/s2340/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.08.01.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="470" data-original-width="2340" height="129" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLj11-2I9kaRhUqejiXWjhVRsQW-MJbmSgU9duqSxHztPJHZ9_nNB3dQlpLeYvMZEL2lc64DCoO-gZQ9yC1AbE0xDsUz-hoXg3rEewyOcuS6EGv02yDpygiprQJMKme14rSaW2vxK70cs7/w640-h129/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.08.01.png" width="640" /></a></div><div><br /></div><div>6.最後命名將此mobileprovision下載</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXQqmdghd7VTZvwkXzMUblgnMdvK4xE6Q26f30SDlIN9QW9XF8QgQfflvfFK_t0YiyHaTrWpf3jmebc2rfBJPHMma4roDsda44Gi7lR1coDFpJLWEY0WTN-qf33YAVn__Kcr2ZIv9QF1ve/s2338/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.08.09.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="552" data-original-width="2338" height="151" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXQqmdghd7VTZvwkXzMUblgnMdvK4xE6Q26f30SDlIN9QW9XF8QgQfflvfFK_t0YiyHaTrWpf3jmebc2rfBJPHMma4roDsda44Gi7lR1coDFpJLWEY0WTN-qf33YAVn__Kcr2ZIv9QF1ve/w640-h151/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.08.09.png" width="640" /></a></div><div>7.重新簽名</div><div><!--?xml version="1.0" encoding="UTF-8"?-->
<div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;">/usr/bin/codesign --preserve-metadata=entitlements --force --verbose --sign "Apple Distribution: XXX" "Payload/Application.app"
</div><div><br /></div></div><div>這邊的<font color="#ff0000" style="font-weight: bold;">Apple Distribution: XXX </font>請自行改成簽名的名稱</div><div><br /></div><div>如果不知道要輸入什麼,可以用Xcode開啟專案來對照一下</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCKS4Hx6uqKqC5Jy_wuaIJMRajwcIZQtIY4tDqDOi2RRaMdt-S6npi7nRa6SrQLKVNuoK5mvNXAjbx71JKZQflGhTWFnkU5gw4e8qVkeWQN3ChkZRGmLrSzxT9mf_P1pvsIWSSc7-Cs7uG/s892/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.18.53.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="392" data-original-width="892" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCKS4Hx6uqKqC5Jy_wuaIJMRajwcIZQtIY4tDqDOi2RRaMdt-S6npi7nRa6SrQLKVNuoK5mvNXAjbx71JKZQflGhTWFnkU5gw4e8qVkeWQN3ChkZRGmLrSzxT9mf_P1pvsIWSSc7-Cs7uG/s640/%25E6%2588%25AA%25E5%259C%2596+2020-08-04+%25E4%25B8%258A%25E5%258D%258810.18.53.png" width="640" /></a></div><div>8.重新壓縮回ipa</div><div><!--?xml version="1.0" encoding="UTF-8"?-->
<div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;">zip -qr "Application.resigned.ipa" Payload
</div><div><br /></div></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div>Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-35167404719017736432020-06-29T21:20:00.005-07:002020-06-29T21:21:42.347-07:00[iOS] JSON<h2 style="-en-clipboard: true;">
<span style="color: #222222; font-family: arial, sans-serif;">JSON</span></h2>
<div style="-en-clipboard: true;">
<span style="-webkit-text-stroke-width: 0px; color: #222222; font-family: arial, sans-serif; font-size: 16px; font-variant-caps: normal; font-variant-ligatures: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">JavaScript Object Notation,是輕量級的資料交換語言,與Swift的字典相當類似,使用key對應value,並且可以儲存String、Int、Double以及Array,透過JSON可以很方便的從別的平台取得資料,接著轉換成Swift程式語言可使用的格式。</span></div>
<div>
<span style="-webkit-text-stroke-width: 0px; font-size: 16px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><br /></span></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
{
</div>
<div>
"a" : "a",
</div>
<div>
"b" : 0,
</div>
<div>
"c" : 0.5,
</div>
<div>
"d" : [1,2,3,4,5],
</div>
<div>
"e" : {
</div>
<div>
"e1": "e"
</div>
<div>
}
</div>
<div>
}
</div>
</div>
<div>
<span style="font-size: 16px;"><br /></span></div>
<div>
<span style="--inversion-type-color: simple; color: #040404; font-family: arial; font-size: 16px;">以上是一個簡單的JSON結構,大括號【 {} 】代表物件,中括號【 [] 】代表陣列,一樣是使用</span></div>
<!--?xml version="1.0" encoding="UTF-8"?-->
<br />
<div>
<span style="--inversion-type-color: simple; color: #040404; font-family: arial; font-size: 16px;">雙引號代表字串,冒號的左方為key,右方為value。</span></div>
<div>
<span style="--inversion-type-color: simple; color: #040404; font-family: arial; font-size: 16px;"><br /></span></div>
<div>
<span style="--inversion-type-color: simple; color: #040404; font-family: arial; font-size: 16px;"><!--?xml version="1.0" encoding="UTF-8"?-->
<div>
<span style="--inversion-type-color: simple;">所以我們使用以上的JSON,拿字串a代表key的話,會取出字串a這個value,依此類推。</span></div>
<div>
<span style="--inversion-type-color: simple;"><br /></span></div>
<div>
<span style="--inversion-type-color: simple;">通常整個JSON是一個字串,我們可以透過轉換將JSON字串轉換成JSON,舉例來說,我們先使用字串構建一個JSON。</span></div>
<div>
<span style="--inversion-type-color: simple;"><br /></span></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
let jsonString = """
</div>
<div>
{
</div>
<div>
"a": "a",
</div>
<div>
"b": 1,
</div>
<div>
"c": 1.1
</div>
<div>
}
</div>
<div>
"""
</div>
</div>
<div>
<br /></div>
<div>
我們可以到網站上驗證我們的JSON字串是否合法
</div>
<div>
<br /></div>
<div>
<a href="https://jsoneditoronline.org/">https://jsoneditoronline.org/</a></div>
<div>
<br /></div>
<div>
確認是一個合法的JSON字串後,我們試著將它轉換成Swift可使用的資料格式,
</div>
<div>
<br /></div>
<div>
前面有提到JSON其實與字典十分類似,因此你可以將JSON字串轉換成字典。 </div>
<div>
<!--?xml version="1.0" encoding="UTF-8"?-->
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
//將JSON字串轉換成Data
</div>
<div>
if let jsonData = jsonString.data(using: .utf8) {
</div>
<div>
do {
</div>
<div>
//透過JSON序列化轉換成自字典物件
</div>
<div>
if let dictionary = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] {
</div>
<div>
print(dictionary["a"]!) //a
</div>
<div>
print(dictionary["b"]!) //1
</div>
<div>
print(dictionary["c"]!) //1.1
</div>
<div>
}
</div>
<div>
} catch {
</div>
<div>
print(error.localizedDescription)
</div>
<div>
}
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
<hr />
<div>
<br /></div>
<div>
但是透過字典來取JSON其實還是有些麻煩,更好的作法應該是將JSON轉換成物件,不管是Class或Struct的形式均可,因此這邊說明如何將JSON轉換成物件。
</div>
<div>
<br /></div>
<div>
首先我們必須要建立一個相同的物件格式,以上面的例子來說
</div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
struct MyJSONModel {
</div>
<div>
var a: String
</div>
<div>
var b: Int
</div>
<div>
var c: Double
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
<div>
接著我們必須遵循Codable協議
</div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
struct MyJSONModel: Codable {
</div>
<div>
var a: String
</div>
<div>
var b: Int
</div>
<div>
var c: Double
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
<div>
如此一來你就可以將JSON轉換成這個結構的實體
</div>
<div>
<br /></div>
<div>
透過JSONDecoder來將JSON Data轉換成結構的實體
</div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
//將JSON字串轉換成Data
</div>
<div>
if let jsonData = jsonString.data(using: .utf8) {
</div>
<div>
do {
</div>
<div>
let jsonDecoder = JSONDecoder()
</div>
<div>
let myJSONModel = try jsonDecoder.decode(MyJSONModel.self, from: jsonData)
</div>
<div>
print(myJSONModel.a) //a
</div>
<div>
print(myJSONModel.b) //1
</div>
<div>
print(myJSONModel.c) //1.1
</div>
<div>
} catch {
</div>
<div>
print(error.localizedDescription)
</div>
<div>
}
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
<div>
當然反過來也可以,你可以將結構實體透過JSONEncoder轉換成JSON Data
</div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
let myJSONModel = MyJSONModel(a: "AA", b: 1, c: 0.2)
</div>
<div>
let jsonEncoder = JSONEncoder()
</div>
<div>
do {
</div>
<div>
let jsonData = try jsonEncoder.encode(myJSONModel)
</div>
<div>
} catch {
</div>
<div>
print(error.localizedDescription)
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
<hr />
<div>
<br /></div>
<div>
有幾個點必須注意的,你的struct或class定義的屬性,一定要與JSON一致,JSON的Value是整數就必須定義成整數,如果有些時候,這個值可能不存在,就必須定義成可選型別。
</div>
<div>
<br /></div>
<div>
變數名稱也必須與JSON的Key相符,若是不相同,則會解析失敗,
</div>
<div>
<br /></div>
<div>
有些時候JSON的Key可能與Swift的命名有些衝突,舉例來說有個JSON格式如下
</div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
{
</div>
<div>
"Name": "Jerry",
</div>
<div>
"Age": 18,
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
<div>
如果我們想要使用這個JSON,且是轉換成struct或class的話,就得這樣定義
</div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
struct User: Codable {
</div>
<div>
var Name: String
</div>
<div>
var Age: Int
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
<div>
但是我們都知道,Swift的命名規則,常數與變數名稱應該為小寫開頭的,因此這樣的命名不是太妥當
</div>
<div>
<br /></div>
<div>
你可以一樣將變數命名成小寫,並增加一個enum CodingKeys,且資料型態為String,實作CodingKey這個Protocol。
</div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
struct User: Codable {
</div>
<div>
var name: String
</div>
<div>
var age: Int
</div>
<div>
</div>
<div>
</div>
<div>
enum CodingKeys: String, CodingKey {
</div>
<div>
case name = "Name"
</div>
<div>
case age = "Age"
</div>
<div>
}
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
<div>
enum的case為你的所有變數名稱,後方則是JSON對應的Key真正的樣子,如此一來,即使JSON的Key與Swift的命名有出入,也可以更換成我們習慣的命名規則。
</div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
let jsonString = """
</div>
<div>
{
</div>
<div>
"Name": "Jerry",
</div>
<div>
"Age": 18
</div>
<div>
}
</div>
<div>
"""
</div>
<div>
<br /></div>
<div>
//將JSON字串轉換成Data
</div>
<div>
if let jsonData = jsonString.data(using: .utf8) {
</div>
<div>
do {
</div>
<div>
let jsonDecoder = JSONDecoder()
</div>
<div>
let user = try jsonDecoder.decode(User.self, from: jsonData)
</div>
<div>
print(user.name) //Jerry
</div>
<div>
print(user.age) //18
</div>
<div>
} catch {
</div>
<div>
print(error.localizedDescription)
</div>
<div>
}
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
</div>
<div>
此外,你可以解析JSONDecoder所拋出的例外</div>
<div>
<br /></div>
<div>
<!--?xml version="1.0" encoding="UTF-8"?-->
<div>
<a href="https://developer.apple.com/documentation/swift/decodingerror">https://developer.apple.com/documentation/swift/decodingerror</a></div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
do {
</div>
<div>
let jsonDecoder = JSONDecoder()
</div>
<div>
let myJSONModel = try jsonDecoder.decode(JSONModel.self, from: jsonData)
</div>
<div>
} catch DecodingError.keyNotFound(let key, let context) {
</div>
<div>
<br /></div>
<div>
} catch DecodingError.typeMismatch(let type, let context) {
</div>
<div>
</div>
<div>
} catch DecodingError.valueNotFound(let type, let context) {
</div>
<div>
</div>
<div>
} catch {
</div>
<div>
</div>
<div>
}
</div>
</div>
<div>
<br /></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
</span></div>
Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-40642785522748955722020-06-19T19:29:00.001-07:002020-06-19T19:29:18.855-07:00[iOS] 使用Carthage來管理第三方套件<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1gLsAVnhsYDrh3djQ4NI-V9uzTlQQL5a0mBWbClVy-g06uYG5rMRGuKaJFHKVlUlx_FkOfKHXauvTVJWK4RhRi_gSCs8d0YYm9RDjBZOlqS08jEgX0vnOAG2sguUkdRv-ZfeFLF6f9rnD/s1600/1_8i-GiRpburAj6_jTI0T5Kw.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="351" data-original-width="1600" height="140" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1gLsAVnhsYDrh3djQ4NI-V9uzTlQQL5a0mBWbClVy-g06uYG5rMRGuKaJFHKVlUlx_FkOfKHXauvTVJWK4RhRi_gSCs8d0YYm9RDjBZOlqS08jEgX0vnOAG2sguUkdRv-ZfeFLF6f9rnD/s640/1_8i-GiRpburAj6_jTI0T5Kw.png" width="640" /></a></div><div class="separator" style="clear: both; text-align: left;"><!--?xml version="1.0" encoding="UTF-8"?-->
<div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; word-break: break-word;"><span style="color: #292929; line-height: 32px;"><font face="Helvetica Neue" style="font-size: 14px;">Carthage是一個較新的管理套件的工具,比起Cocoapods使用起來更加地方便且輕巧。</font></span></span></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><font color="#292929"><span style="line-height: 32px;"><a href="https://github.com/Carthage/Carthage">https://github.com/Carthage/Carthage</a></span></font></font></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; word-break: break-word;"><span style="color: #292929; line-height: 32px;"><font face="Helvetica Neue" style="font-size: 14px;">安裝Carthage</font></span></span></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; word-break: break-word;"><span style="color: #292929; line-height: 32px;"><font face="Helvetica Neue" style="font-size: 14px;">打開終端機後輸入,使用Homebrew進行安裝</font></span></span></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">brew install carthage</font></div></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><span style="color: #292929; letter-spacing: -0.003em; line-height: 32px; word-break: break-word;">如果沒有安裝Homebrew的朋友們,可以點選以下的網址安裝</span></font></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><a href="https://brew.sh/"><font face="Helvetica Neue" style="font-size: 14px;">https://brew.sh/</font></a></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><span style="color: #292929; letter-spacing: -0.003em; line-height: 32px; word-break: break-word;">安裝完畢後,輸入以下的指令確認有反應</span></font></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">Carthage version</font></div></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; word-break: break-word;"><span style="color: #292929; line-height: 32px;"><font face="Helvetica Neue" style="font-size: 14px;">確認安裝成功後,我們試著開啟一個專案來使用看看。</font></span></span></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; word-break: break-word;"><span style="color: #292929; line-height: 32px;"><font face="Helvetica Neue" style="font-size: 14px;">找一個有支援Carthage的第三方套件,通常會在套件頁面會有個Tag表示有支援Carthage</font></span></span></div><div style="background-color: white; letter-spacing: -0.003em; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; word-break: break-word;"><span style="color: #292929; line-height: 32px;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDWX2WIn4sB_6T3astFMi5D_U6GgP6X07SPSW73PtjcmFr15WelJVA1CilG_My-eD8zq1sXm7OQ7bFohPxOnm9xJvAB8LpEyULzHjaL63weuBjnrUhbReY4PIcLqOpK5F0-jgMrGoUK9yP/s1316/1_SQj9ry6hmtsW4IwgWcKpVg.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="386" data-original-width="1316" height="185" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDWX2WIn4sB_6T3astFMi5D_U6GgP6X07SPSW73PtjcmFr15WelJVA1CilG_My-eD8zq1sXm7OQ7bFohPxOnm9xJvAB8LpEyULzHjaL63weuBjnrUhbReY4PIcLqOpK5F0-jgMrGoUK9yP/w625-h185/1_SQj9ry6hmtsW4IwgWcKpVg.png" width="625" /></a></div><!--?xml version="1.0" encoding="UTF-8"?-->
<div><span style="letter-spacing: -0.063px;"><font face="Helvetica Neue" style="font-size: 14px;">接著到專案目錄底下新增一個Cartfile檔案,可以使用熟悉的文字編輯器新增此檔案。</font></span></div><div><span style="letter-spacing: -0.063px;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVqpx1kVlDeblS4XXNK7BI9glNg0GrfKhyphenhyphen5qdAJhO5TedYfT6CGsspIgt4yoYnrXE4osw56fQEgw2yT88Q0gFNQSyGSB1O0ywTkQpHthvGnnHao0jBk4wZ12xJ4sYTs1uRaH41VrtypGPR/s1400/1_ZPZJ27HtWn9cfbwukxv3iQ.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="792" data-original-width="1400" height="354" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVqpx1kVlDeblS4XXNK7BI9glNg0GrfKhyphenhyphen5qdAJhO5TedYfT6CGsspIgt4yoYnrXE4osw56fQEgw2yT88Q0gFNQSyGSB1O0ywTkQpHthvGnnHao0jBk4wZ12xJ4sYTs1uRaH41VrtypGPR/w625-h354/1_ZPZJ27HtWn9cfbwukxv3iQ.png" width="625" /></a></div><div class="separator" style="clear: both; text-align: left;"><!--?xml version="1.0" encoding="UTF-8"?-->
<div><font face="Helvetica Neue" style="font-size: 14px;"><span style="letter-spacing: -0.063px;">接著我們加入以下的文字,代表我們要使用</span><span style="background-color: #f2f2f2; letter-spacing: -0.063px;">Kingfisher</span><span style="letter-spacing: -0.063px;">這個套件</span></font></div><div><span style="letter-spacing: -0.063px;"><font face="Helvetica Neue" style="font-size: 14px;"><br /></font></span></div><div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">github "onevcat/Kingfisher"</font></div></div><div><font face="Helvetica Neue" style="font-size: 14px;"><br /></font></div><div><span style="letter-spacing: -0.063px;"><font face="Helvetica Neue" style="font-size: 14px;">文字的內容通常於套件提供者的Github上面會提供,接著輸入指令下載套件</font></span></div><div><span style="letter-spacing: -0.063px;"><font face="Helvetica Neue" style="font-size: 14px;"><br /></font></span></div><div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">carthage update</font></div></div><div><font face="Helvetica Neue" style="font-size: 14px;"><br /></font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;">這邊必須要等一段時間,Carthage會從Github上面下載套件,並且將它打包成Framework,如果你使用的套件有支援macOS、tvOS、watchOS的話,也會一併下載,你可以依照你的需求決定要下載哪個檔案,這樣可以比較省時。</font></span></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;">所以你可以將指令改成以下的樣子</font></span></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;">iOS</font></span></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">carthage update --platform iOS</font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;">macOS</font></span></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">carthage update --platform macOS</font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;">tvOS</font></span></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">carthage update --platform tvOS</font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;">watchOS</font></span></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">carthage update --platform watchOS</font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><span style="letter-spacing: -0.063px;">安裝完畢後,你的專案會多出Carthage的資料夾,</span></font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><span style="letter-spacing: -0.063px;">我們可以從裡面的Build資料夾中看到它編譯完成的Framework。</span></font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQdHUrP5bpD_SG8lD1kJ8gcT8ecNUkRXupt4Cqanr9-aCyS4ESVxXyPeDpPKygtGEhAeXsC3TsparezorC3lY3Wak3tOfQrer8rBOV7rJzjAI5323D4FPmf6uujr_wxLgYbBF7reeInr3p/s1400/1_J5lM1dq8XrlEqfkdD0ctXw.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="617" data-original-width="1400" height="275" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQdHUrP5bpD_SG8lD1kJ8gcT8ecNUkRXupt4Cqanr9-aCyS4ESVxXyPeDpPKygtGEhAeXsC3TsparezorC3lY3Wak3tOfQrer8rBOV7rJzjAI5323D4FPmf6uujr_wxLgYbBF7reeInr3p/w625-h275/1_J5lM1dq8XrlEqfkdD0ctXw.png" width="625" /></a></div><div class="separator" style="clear: both; text-align: left;"><!--?xml version="1.0" encoding="UTF-8"?-->
<div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;">接下來我們開啟我們的專案,並且於Build Phases增加一個 Run Script Phase</span></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"></div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyEMVP0b3VTiAuoPCH8KAWEEitLJh01jKxQ_duQRaDITwRIrMNhi2xouTEjQEioqirb6DZ0DQsVzA8uHp69qs1r3pUk2a0E-tqq7TER5Hl0Zy0sOJ4ZycKtGaBtzWOxjy2vuO-xXnsUbv3/s1400/1_VT2dN1wi9VvDXLzv6FwY8w.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="490" data-original-width="1400" height="219" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyEMVP0b3VTiAuoPCH8KAWEEitLJh01jKxQ_duQRaDITwRIrMNhi2xouTEjQEioqirb6DZ0DQsVzA8uHp69qs1r3pUk2a0E-tqq7TER5Hl0Zy0sOJ4ZycKtGaBtzWOxjy2vuO-xXnsUbv3/w625-h219/1_VT2dN1wi9VvDXLzv6FwY8w.png" width="625" /></a></div></font><!--?xml version="1.0" encoding="UTF-8"?-->
<div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><span style="letter-spacing: -0.063px;">接著將以下的內容複製到Shell之中</span><br /></font></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">/usr/local/bin/carthage copy-frameworks</font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;">Input Files增加你的套件路徑</span><br /></font></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">$(SRCROOT)/Carthage/Build/iOS/Kingfisher.framework</font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;">Output Files也增加套件路徑</font></span></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font face="Helvetica Neue" style="font-size: 14px;">$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Kingfisher.framework</font></div></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><span style="background-color: transparent;">Input 與 Output基本上就只有最後一段framework名稱不同,其他就複製貼上就可以了,如果你有多個套件,記得每個都要加上Input與Output。</span><br /></font></div><div><font face="Helvetica Neue" style="font-size: 14px;">此時你的Run Script檔案應該會像這個樣子</font></div><div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6vMsjoogqQDH5kR7YKphtotM92TiiRCYldwYmoPCn2j68mUlCSVyO9Fx0COEbxqNfh52y_f0PoImcwioCimwYESggG1vM_sjlCVThvkqj_ZeYgVcXWuDdRjw9wBsHIlNGob-WVNp0ci6A/s1366/1_ZUHrlSiwzbPld0-bLugebg.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1318" data-original-width="1366" height="604" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6vMsjoogqQDH5kR7YKphtotM92TiiRCYldwYmoPCn2j68mUlCSVyO9Fx0COEbxqNfh52y_f0PoImcwioCimwYESggG1vM_sjlCVThvkqj_ZeYgVcXWuDdRjw9wBsHIlNGob-WVNp0ci6A/w625-h604/1_ZUHrlSiwzbPld0-bLugebg.png" width="625" /></a></div><div class="separator" style="clear: both; text-align: left;"><!--?xml version="1.0" encoding="UTF-8"?-->
<div style="font-family: medium-content-serif-font, Georgia, Cambria, "Times New Roman", Times, serif; letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><font style="font-size: 14px;">接下來,導入套件到你的專案之中</font></span></div><div style="font-family: medium-content-serif-font, Georgia, Cambria, "Times New Roman", Times, serif; letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><font style="font-size: 14px;">點選Targets -> Build Phases -> Link Binary With Libraries</font></span></div><div style="font-family: medium-content-serif-font, Georgia, Cambria, "Times New Roman", Times, serif; letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiX6Ix7kKp1GEpZeqF3WXZxJYlEO1SEvgqpZFkxkgk9exKTEFKqOsKBna_pw2IvT5vm8oAkwgrdL3vhdF3YNlTRRQ9K_h4AdGF_OgwToKJwYzot0J5VQ5rhJ5v4nCbqygqqPxtvzQrdsuj/s1400/1_sdrbiQnka7IF_t70pUvPIA.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="745" data-original-width="1400" height="333" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiX6Ix7kKp1GEpZeqF3WXZxJYlEO1SEvgqpZFkxkgk9exKTEFKqOsKBna_pw2IvT5vm8oAkwgrdL3vhdF3YNlTRRQ9K_h4AdGF_OgwToKJwYzot0J5VQ5rhJ5v4nCbqygqqPxtvzQrdsuj/w625-h333/1_sdrbiQnka7IF_t70pUvPIA.png" width="625" /></a></div><div class="separator" style="clear: both; text-align: center;"><!--?xml version="1.0" encoding="UTF-8"?-->
<div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; text-align: start; word-break: break-word;"><font style="font-size: 14px;"><span style="letter-spacing: -0.063px;">接著點選 + 按鈕,到Build資料夾中選擇套件</span><br /></font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; text-align: start; word-break: break-word;"></div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_LUGAHlmoNIFsuJLRBXiBlU9bAXRBVwkzj51jWeAvFSVtYfkrcSJMvaVFA83UtdaKXxVJQa1jg6mdrWkm3BAgK9cK2fnNpsLpdqSMMqDuxkDTVA5xGq_dS5C0qIBkG0WHDjM_CL_jB4Ox/s1400/1_xJhaFahvc7WQLnnG8TUS9g.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="827" data-original-width="1400" height="369" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_LUGAHlmoNIFsuJLRBXiBlU9bAXRBVwkzj51jWeAvFSVtYfkrcSJMvaVFA83UtdaKXxVJQa1jg6mdrWkm3BAgK9cK2fnNpsLpdqSMMqDuxkDTVA5xGq_dS5C0qIBkG0WHDjM_CL_jB4Ox/w625-h369/1_xJhaFahvc7WQLnnG8TUS9g.png" width="625" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjozfi_KJyEixpw4cCMqB8cZvA9aEWsl2iecx5AXDLSgCJszQdN1Cf583OFNrZBgvqrE1267mm7wFsfz1ERnx5HebxMMXbx6v8q7TQ06edKvWsj5sIj1LkPyCDXngqAQ_sf5cycb3ficzhR/s1400/1_2Rh5RCQCKgnQUSJYOMSvtQ.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="329" data-original-width="1400" height="148" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjozfi_KJyEixpw4cCMqB8cZvA9aEWsl2iecx5AXDLSgCJszQdN1Cf583OFNrZBgvqrE1267mm7wFsfz1ERnx5HebxMMXbx6v8q7TQ06edKvWsj5sIj1LkPyCDXngqAQ_sf5cycb3ficzhR/w625-h148/1_2Rh5RCQCKgnQUSJYOMSvtQ.png" width="625" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><font style="font-size: 14px;"><!--?xml version="1.0" encoding="UTF-8"?-->
<div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;">最後你就可以在程式碼中使用套件了,別忘了要import唷</span></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><div><font style="font-size: 14px;">import UIKit</font></div><div><font style="font-size: 14px;">import Kingfisher</font></div><div><font style="font-size: 14px;"><br /></font></div><div><font style="font-size: 14px;">class ViewController: UIViewController {</font></div><div><font style="font-size: 14px;"> </font></div><div><font style="font-size: 14px;"> @IBOutlet weak var imageView: UIImageView!</font></div><div><font style="font-size: 14px;"> </font></div><div><font style="font-size: 14px;"> override func viewDidLoad() {</font></div><div><font style="font-size: 14px;"> super.viewDidLoad()</font></div><div><font style="font-size: 14px;"> let url = URL(string: "https://i.imgur.com/aMMk5ri.jpg")</font></div><div><font style="font-size: 14px;"> imageView.kf.setImage(with: url)</font></div><div><font style="font-size: 14px;"> }</font></div><div><font style="font-size: 14px;"><br /></font></div><div><font style="font-size: 14px;">}</font></div></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;">接下來分享一些Carthage的指令</span><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><div><font style="font-size: 14px;"># 版號 >= 5.0</font></div><div><font style="font-size: 14px;">github "onevcat/Kingfisher" >= 5.0</font></div><div><font style="font-size: 14px;"><br /></font></div><div><font style="font-size: 14px;"># 版號 5.x</font></div><div><font style="font-size: 14px;">github "onevcat/Kingfisher" ~> 5.0</font></div><div><font style="font-size: 14px;"><br /></font></div><div><font style="font-size: 14px;"># 版號 5.0</font></div><div><font style="font-size: 14px;">github "onevcat/Kingfisher" == 5.0</font></div><div><font style="font-size: 14px;"><br /></font></div><div><font style="font-size: 14px;"># 最新版</font></div><div><font style="font-size: 14px;">github "onevcat/Kingfisher"</font></div><div><font style="font-size: 14px;"><br /></font></div><div><font style="font-size: 14px;"># 指定 Git branch</font></div><div><font style="font-size: 14px;">github "onevcat/Kingfisher" "branch"</font></div></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><span style="letter-spacing: -0.003em; line-height: 32px; word-break: break-word;">只更新某個套件</span><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;"><font style="font-size: 14px;">carthage update Kingfisher</font></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><br /></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"></div></font></span></div></div><font face="Helvetica Neue" style="font-size: 14px;"><br /></font></div></div><div style="letter-spacing: -0.003em; line-height: 32px; margin-bottom: 1em; margin-top: 1em; word-break: break-word;"><font face="Helvetica Neue" style="font-size: 14px;"><span style="letter-spacing: -0.063px;"><br /></span></font></div></div><font face="Helvetica Neue" style="font-size: 14px;"><br /></font></span></div></span></span></div></div>Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-73136678681108977482020-06-18T19:22:00.001-07:002020-06-18T19:23:06.725-07:00[iOS - Swift] extension<div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;">extension,擴展,用於在既有的Class Struct Enum上增加額外的功能。</div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div><div class="en-code" style="background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; margin: 0px; padding: 8px; text-size-adjust: auto;"><div style="box-sizing: border-box; margin: 0px; padding: 0px;">class MyClass {</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;"> </div><div style="box-sizing: border-box; margin: 0px; padding: 0px;">}</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;"><br style="box-sizing: border-box;" /></div><div style="box-sizing: border-box; margin: 0px; padding: 0px;">extension MyClass {</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;"> func sayHello() {</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;"> print("Hello")</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;"> }</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;">}</div></div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div><div class="en-code" style="background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; margin: 0px; padding: 8px; text-size-adjust: auto;"><div style="box-sizing: border-box; margin: 0px; padding: 0px;">let myClass = MyClass()</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;">myClass.sayHello()</div></div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;">也可以於原生提供的Class增加額外的功能。</div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div><div class="en-code" style="background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; margin: 0px; padding: 8px; text-size-adjust: auto;"><div style="box-sizing: border-box; margin: 0px; padding: 0px;">extension String {</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;"> func toIntValue() -> Int? {</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;"> return Int(self)</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;"> }</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;">}</div></div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div><div class="en-code" style="background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; margin: 0px; padding: 8px; text-size-adjust: auto;"><div style="box-sizing: border-box; margin: 0px; padding: 0px;">let string = "3"</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;">print(string.toIntValue())</div></div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;">這種情況叫做Category,通常會開一個新的檔案,命名為要擴展的Class+</div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;">例如:</div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;">String+.swift</div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;">擴展也能拿來實作Protocol</div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div><div class="en-code" style="background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; margin: 0px; padding: 8px; text-size-adjust: auto;"><div style="box-sizing: border-box; margin: 0px; padding: 0px;">extension ViewController: UITableViewDelegate {</div><div style="box-sizing: border-box; margin: 0px; padding: 0px;"><br style="box-sizing: border-box;" /></div><div style="box-sizing: border-box; margin: 0px; padding: 0px;">}</div></div><div style="box-sizing: border-box; caret-color: rgb(51, 51, 51); color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; font-size: 14px; margin: 0px; padding: 0px; text-size-adjust: auto;"><br style="box-sizing: border-box;" /></div>Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-79345238045738944422020-06-17T21:00:00.003-07:002020-06-17T21:01:04.109-07:00[iOS - Swift] UIColor<div style="-en-clipboard: true; margin-bottom: 1em; margin-top: 1em;">
<span style="-en-paragraph: true;">iOS用於表示顏色的Class,iOS有提供一些已經有的顏色,也可以使用自己的方法來創建。</span></div>
<div style="margin-bottom: 1em; margin-top: 1em;">
</div>
<div style="margin-bottom: 1em; margin-top: 1em;">
</div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
UIColor.red
</div>
<div>
UIColor.blue
</div>
<div>
UIColor.yellow
</div>
</div>
<div>
<br /></div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
<div>
let customColor = UIColor(red: 100/255,
</div>
<div>
green: 100/255,
</div>
<div>
blue: 100/255,
</div>
<div>
alpha: 1)
</div>
</div>
<div>
<br /></div>
<div style="margin-bottom: 1em; margin-top: 1em;">
<span style="-en-paragraph: true;">顏色的組成為RGBA,光的三原色,紅綠藍,Alpha則為透明度,每個值可從0~255,總共有256種變化,</span></div>
<div style="margin-bottom: 1em; margin-top: 1em;">
<span style="-en-paragraph: true;">可呈現的顏色有 256 * 256 * 256種顏色,幾乎所有的顏色都有辦法顯示。</span></div>
<!--?xml version="1.0" encoding="UTF-8"?-->
<br />
<div style="margin-bottom: 1em; margin-top: 1em;">
也可以使用Assets來管理顏色</div>
<div style="margin-bottom: 1em; margin-top: 1em;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCNb_fvJ7J-QtB0-MmeZl_YyOOjH6vKx4PucEwP1oBqJ5MrOZX8VP4RHBSiZN9Se51oQBLVcuJY-ZhTyd8BvJDkCNl9sgHnCzWe0dz6MFhkmd4oBkBkJxmFCASMKDwZwME9g4RVtkIa20o/s1600/%25E6%2588%25AA%25E5%259C%2596+2020-02-03+%25E4%25B8%258B%25E5%258D%25883.58.47.png" imageanchor="1"><img border="0" height="428" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCNb_fvJ7J-QtB0-MmeZl_YyOOjH6vKx4PucEwP1oBqJ5MrOZX8VP4RHBSiZN9Se51oQBLVcuJY-ZhTyd8BvJDkCNl9sgHnCzWe0dz6MFhkmd4oBkBkJxmFCASMKDwZwME9g4RVtkIa20o/s640/%25E6%2588%25AA%25E5%259C%2596+2020-02-03+%25E4%25B8%258B%25E5%258D%25883.58.47.png" width="640" /></a> </div>
<div style="margin-bottom: 1em; margin-top: 1em;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFf7lldmEN-X89tsUVWfqEoOpUNg4ZHa4BFM0S3BTAyNmcITpOjkj72X2OmYjXb-ZrDQv-BUoMmYV1ky8kxqz7QRM2PLRlDigMVIIRiQWIygtg-cohLNSMLxv4YaSZagNPfg026wMIARvH/s1600/%25E6%2588%25AA%25E5%259C%2596+2020-02-03+%25E4%25B8%258B%25E5%258D%25883.59.12.png" imageanchor="1"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFf7lldmEN-X89tsUVWfqEoOpUNg4ZHa4BFM0S3BTAyNmcITpOjkj72X2OmYjXb-ZrDQv-BUoMmYV1ky8kxqz7QRM2PLRlDigMVIIRiQWIygtg-cohLNSMLxv4YaSZagNPfg026wMIARvH/s640/%25E6%2588%25AA%25E5%259C%2596+2020-02-03+%25E4%25B8%258B%25E5%258D%25883.59.12.png" width="640" /></a></div>
<div style="margin-bottom: 1em; margin-top: 1em;">
<!--?xml version="1.0" encoding="UTF-8"?-->
<div style="-en-clipboard: true; margin-bottom: 1em; margin-top: 1em;">
接著透過此方法並輸入你命名的名稱即可取得該顏色
</div>
<div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); box-sizing: border-box; color: #333333; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 12px; padding: 8px;">
view.backgroundColor = UIColor(named: "MyColor")
</div>
<div style="margin-bottom: 1em; margin-top: 1em;">
此外,你可以透過Color Literal來直接指定顏色,於程式碼區塊輸入Color Literal,並且點選它</div>
<div style="margin-bottom: 1em; margin-top: 1em;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHPAXc-nBumhD3O6Nf0TPy0vA3mLV_qQFsK-HFNL-W5vXV3zFTv-AUGVaSf4noVpzdWe9DeMmu_YkbjPFrSJhucfa-h3-E28VuDBvTkEo48LCo26H7reT8DTHONyFU96Jo0PJBbtwg0BUU/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-06-18+%25E4%25B8%258A%25E5%258D%258811.30.26.png" imageanchor="1"><img border="0" height="140" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHPAXc-nBumhD3O6Nf0TPy0vA3mLV_qQFsK-HFNL-W5vXV3zFTv-AUGVaSf4noVpzdWe9DeMmu_YkbjPFrSJhucfa-h3-E28VuDBvTkEo48LCo26H7reT8DTHONyFU96Jo0PJBbtwg0BUU/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-06-18+%25E4%25B8%258A%25E5%258D%258811.30.26.png" width="640" /></a></div>
<div style="margin-bottom: 1em; margin-top: 1em;">
<!--?xml version="1.0" encoding="UTF-8"?-->
<div style="-en-clipboard: true; margin-bottom: 1em; margin-top: 1em;">
點選顏色方塊,就可以直接於程式碼之中選擇你想要的顏色
</div>
<div style="margin-bottom: 1em; margin-top: 1em;">
</div>
</div>
<div style="margin-bottom: 1em; margin-top: 1em;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnp2gZYolwitIGaa5m5XGbW3cetTFcjBB3d1-SWdJaZJffG50OcGOUyizGKS-l-9Q5VnKG6OHxbz7KqyWZgfkpsrBTN05ViOy0Yi_93FzYtKKqIqPK_9hP5J7-So9oGEqnkUKqKP63j9pG/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-06-18+%25E4%25B8%258A%25E5%258D%258811.58.05.png" imageanchor="1"><img border="0" height="490" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnp2gZYolwitIGaa5m5XGbW3cetTFcjBB3d1-SWdJaZJffG50OcGOUyizGKS-l-9Q5VnKG6OHxbz7KqyWZgfkpsrBTN05ViOy0Yi_93FzYtKKqIqPK_9hP5J7-So9oGEqnkUKqKP63j9pG/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-06-18+%25E4%25B8%258A%25E5%258D%258811.58.05.png" width="640" /></a> </div>
<div style="margin-bottom: 1em; margin-top: 1em;">
</div>
</div>
Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-7760534147242025072020-06-17T19:51:00.001-07:002020-06-17T19:52:04.406-07:00[iOS - Swift] UIPickerView<!--?xml version="1.0" encoding="UTF-8"?-->
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3T_WetDX8Z-KZB1m8fc6EUOL5fatAhR3oHQZcJm7H2iKysFf6TrS3z5T0wTr7L7SrJ-G8L_VKWFOdLuSv7ctE8ZyGECQtxbbNu3Rqa-G5j2pKtoB5_uAuRAaRKhodp-JDRujeEKnYySzC/s724/%25E6%2588%25AA%25E5%259C%2596+2020-02-16+%25E4%25B8%258B%25E5%258D%258810.14.35.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="406" data-original-width="724" height="280" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3T_WetDX8Z-KZB1m8fc6EUOL5fatAhR3oHQZcJm7H2iKysFf6TrS3z5T0wTr7L7SrJ-G8L_VKWFOdLuSv7ctE8ZyGECQtxbbNu3Rqa-G5j2pKtoB5_uAuRAaRKhodp-JDRujeEKnYySzC/w500-h280/%25E6%2588%25AA%25E5%259C%2596+2020-02-16+%25E4%25B8%258B%25E5%258D%258810.14.35.png" width="500" /></a></div><div><br /></div><div><br /></div><div>透過滾動提供使用者選擇的一種View,必須實作UIPickerDataSource與UIPickerViewDelegate兩個Protocol才可使用,
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>extension ViewController: UIPickerViewDataSource {
</div><div>
</div><div> ///總共有幾個Component
</div><div> func numberOfComponents(in pickerView: UIPickerView) -> Int {
</div><div> return 2
</div><div> }
</div><div>
</div><div> ///每個Component有幾個Row
</div><div> func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
</div><div> return 3
</div><div> }
</div><div>
</div><div>}
</div></div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>extension ViewController: UIPickerViewDelegate {
</div><div> ///所顯示的Title
</div><div> func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
</div><div> return "\(component), \(row)"
</div><div> }
</div><div>}
</div></div><div><br /></div><div>最後別忘了指定成self
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>pickerView.dataSource = self
</div><div>pickerView.delegate = self
</div></div><div><br /></div><div>你可以透過此函式來得知使用者是選擇哪一個Row
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"> pickerView.selectedRow(inComponent: 0) //第0個Component選擇了第幾個Row
</div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div>Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-31412034753424322672020-06-17T19:47:00.002-07:002020-06-17T19:49:17.602-07:00[iOS - Swift] NotificationCenter<!--?xml version="1.0" encoding="UTF-8"?-->
<div style="-en-clipboard: true; margin-bottom: 1em; margin-top: 1em;">消息通知機制,可能有時候你會希望某個事情發生時,另外一個物件或頁面想到得知訊息。</div><div>舉一個生活上的例子,你訂閱了某個粉絲團,如果粉絲團發布一個訊息時,你可以收到。
</div><div style="margin-bottom: 1em; margin-top: 1em;">首先你必須先加入觀察者,並且設定對應的Key與方法</div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>///加入觀察者
</div><div>NotificationCenter.default.addObserver(self,
</div><div> selector: #selector(ViewController.test),
</div><div> name: NSNotification.Name("Test123"),
</div><div> object: nil)
</div></div><div style="margin-bottom: 1em; margin-top: 1em;">對應的方法</div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>@objc private func test() {
</div><div> print("Hello Test!")
</div><div>}
</div></div><div style="margin-bottom: 1em; margin-top: 1em;">有一點像是Target - Action的形式,透過selector來指定要執行的方法。</div><div>接下來你只需要對通知中心發送通知,就可以觸發這個方法。
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>///發送訊息
</div><div>NotificationCenter.default.post(name: NSNotification.Name("Test123"), object: nil)
</div></div><div><br /></div><div>接下來,你可以試著增加一個Class,並且也加入觀察者,Key使用相同的文字。
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>class MyClass {
</div><div>
</div><div> func addObserver() {
</div><div> NotificationCenter.default.addObserver(self,
</div><div> selector: #selector(MyClass.test),
</div><div> name: NSNotification.Name("Test123"),
</div><div> object: nil)
</div><div> }
</div><div>
</div><div> @objc private func test() {
</div><div> print("My Class Test")
</div><div> }
</div><div>}
</div></div><div><br /></div><div style="margin-bottom: 1em; margin-top: 1em;">接著執行一樣的程式碼試試看,你會發現兩邊都被觸發了,因為Key是相同的,所以他視為同樣的事件,因此兩邊都被觸發了。
</div><div style="margin-bottom: 1em; margin-top: 1em;">知道了以上的特性,使用NotificationCenter時必須要小心,Key可能命名的獨一無二一點,若是與其他人相同,可能會發生意想不到的事情。</div><div>發送通知時,可以夾帶屬性,使用UserInfo這個參數就可以了,
</div><div style="margin-bottom: 1em; margin-top: 1em;">首先我們把接收的方法改一下,並且將加入觀察者的方法也改了一下。</div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>///加入觀察者
</div><div>NotificationCenter.default.addObserver(self,
</div><div> selector: #selector(ViewController.test(notification:)),
</div><div> name: NSNotification.Name("Test123"),
</div><div> object: nil)
</div></div><div><br /></div><div>接收的方法改成有傳入值的方法。
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>@objc private func test(notification: NSNotification) {
</div><div> if let userInfoData = notification.userInfo?["QQ"] as? String {
</div><div> print(userInfoData)
</div><div> }
</div><div>}
</div></div><div><br /></div><div>最後,發送通知的時候,改成以下的方法,多傳入userInfo即可。
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>///發送訊息,並且傳送資料
</div><div>NotificationCenter.default.post(name: NSNotification.Name("Test123"),
</div><div> object: nil,
</div><div> userInfo: ["QQ":"QQ123"])
</div></div><div style="margin-bottom: 1em; margin-top: 1em;">這樣就可以傳入資料了。</div><div>接著如果要移除觀察者的話,可以使用以下的語法
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>NotificationCenter.default.removeObserver(self)
</div><div><br /></div><div>///移除特定通知
</div><div>NotificationCenter.default.removeObserver(self, name: NSNotification.Name("Test123"), object: nil)
</div></div><div><br /></div><div><span style="white-space: pre;">這個算是一個滿方便的東西,但是要小心,Key必須小心管理,</span></div><div><span style="white-space: pre;">不需要通知時,記得移除通知,避免發生意外。</span></div><div><br /></div>Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-31192858433577625602020-06-17T19:43:00.002-07:002020-06-17T19:48:04.506-07:00[iOS - Swift] Date的使用方式<!--?xml version="1.0" encoding="UTF-8"?-->
<div style="-en-clipboard: true; margin-bottom: 1em; margin-top: 1em;">Date是專門用來處理有關時間的一個類別。</div><div>我們可以簡單的透過以下的程式碼來取得當前時間。
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;">let date = Date()
</div><div><br /></div><div>接著透過DateFormatter來進行時間的轉換,因為我們可能會需要將時間轉換成字串,以便顯示,或者進行處理。</div><div><br /></div><div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>///取得當前時間
</div><div>let date = Date()
</div><div>///時間轉換成字串
</div><div>let dateFormatter = DateFormatter()
</div><div>dateFormatter.dateFormat = "yyyy/MM/dd"
</div><div>print(dateFormatter.string(from: date))</div></div><div style="margin-bottom: 1em; margin-top: 1em;"><!--?xml version="1.0" encoding="UTF-8"?-->
<div style="-en-clipboard: true; margin-bottom: 1em; margin-top: 1em;">我們可以透過網站得知一些時間的格式應該怎麽使用</div><div><a href="https://nsdateformatter.com/">https://nsdateformatter.com/</a></div><div><br /></div><div>透過設定dateFormat,來讓Date轉換成你想要的時間格式。
</div><div>如果轉換出來的結果可能會依照語系的不同,可以經由設定語系來更改
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>///取得當前時間
</div><div>let date = Date()
</div><div>///時間轉換成字串
</div><div>let dateFormatter = DateFormatter()
</div><div>///設定語系
</div><div>dateFormatter.locale = Locale(identifier: "zh_tw")
</div><div>dateFormatter.dateFormat = "MMMM"
</div><div>print(dateFormatter.string(from: date))</div></div><div><br /></div><div>當然,你也可以透過文字轉換回Date</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>let dateFormatter = DateFormatter()
</div><div>dateFormatter.locale = Locale(identifier: "zh_tw")
</div><div>dateFormatter.dateFormat = "yyyy/MM/dd"
</div><div>if let myDate = dateFormatter.date(from: "2018/12/21") {
</div><div> print(myDate)
</div><div>}
</div></div><div style="margin-bottom: 1em; margin-top: 1em;">至於日期的增減則可以使用Calendar來處理</div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>let date = Date()
</div><div>///加三天
</div><div>let newDate = Calendar.current.date(byAdding: .day, value: 3, to: date)!
</div><div>let dateFormatter = DateFormatter()
</div><div>dateFormatter.locale = Locale(identifier: "zh_tw")
</div><div>dateFormatter.dateFormat = "yyyy/MM/dd"
</div><div>print(dateFormatter.string(from: newDate))
</div></div><div><br /></div><div>日期的比較,因為Date有實作Comparable這個Protocol,因此可以很簡單的使用> < = 來進行日期的比較。
</div><div><br /></div><div style="-en-codeblock: true; background-color: #fbfaf8; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing: border-box; color: #333333; font-family: monaco, menlo, consolas, "courier new", monospace; font-size: 12px; padding: 8px;"><div>let date = Date()
</div><div>let newDate = Calendar.current.date(byAdding: .day, value: 3, to: date)!
</div><div>if date < newDate {
</div><div> print("Date < NewDate")
</div><div>}
</div><div>if date > newDate {
</div><div> print("Date > newDate")
</div><div>}
</div><div>if date == newDate {
</div><div> print("Date == newDate")
</div><div>} </div></div></div></div>Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-17593897036603823762020-01-02T19:18:00.001-08:002020-01-02T19:18:16.128-08:00[iOS] 讓ScrollView顯示indicators有時候有些畫面可以捲動,可是使用者不一定知道這個畫面可以捲動,你可以於每次顯示此畫面時,呼叫flashScrollIndicators函式,讓ScrollView相關類別顯示一下Indicators,這樣會讓使用者知道這個頁面可以捲動。<br />
<br />
<script src="https://gist.github.com/Aiur3908/f53c853038efba78b7661e12845a4fc0.js"></script>
使用效果就會像是這個樣子,可捲動的Indicators會顯示出來。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCvoUxt4pwylzIna7xo_Ar-KkzhCKbtEUvqbjRD4k1177vrKqtBU9HCuOK4-gspH6P-YXNjMQM-jqt3fGPIfjybEAp5smU6hClBq4DKdgVlEcHMmm4I-3czTHVN8pogM6uQarvrmMinyug/s1600/%25E6%2588%25AA%25E5%259C%2596+2020-01-03+%25E4%25B8%258A%25E5%258D%258811.17.37.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1582" data-original-width="780" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCvoUxt4pwylzIna7xo_Ar-KkzhCKbtEUvqbjRD4k1177vrKqtBU9HCuOK4-gspH6P-YXNjMQM-jqt3fGPIfjybEAp5smU6hClBq4DKdgVlEcHMmm4I-3czTHVN8pogM6uQarvrmMinyug/s640/%25E6%2588%25AA%25E5%259C%2596+2020-01-03+%25E4%25B8%258A%25E5%258D%258811.17.37.png" width="314" /></a></div>
<br />
<br />Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-43464135915496780532019-11-12T22:52:00.002-08:002019-11-13T17:46:55.736-08:00[iOS] 等寬字體有時候會需要等寬字體,像是顯示數字時,希望位數相同的可以對齊,若是你設定的字體非等寬字體的話,就會像以下這個樣子。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_QYwXr_oL2SZX6ZuJEwPldim0e_nK56haKslUVPxLiwA6jjFlwEbjJ8Nz1akg3bIkzOYBjwmiDWsSZ9p49Edpqfv87tqR6_h_TUNs1n-a_933slw51KmC0CwpTUKJyJPotPq_cNas0Pnx/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.46.17.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="161" data-original-width="191" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_QYwXr_oL2SZX6ZuJEwPldim0e_nK56haKslUVPxLiwA6jjFlwEbjJ8Nz1akg3bIkzOYBjwmiDWsSZ9p49Edpqfv87tqR6_h_TUNs1n-a_933slw51KmC0CwpTUKJyJPotPq_cNas0Pnx/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.46.17.png" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
你可以使用<b>Courier</b>或<b>Menlo</b>兩種等寬字體來解決此問題<br />
<br />
Courier<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieMaqG_pSa99n8stlqX-rJyjEfSdi7W1KpBLlv0MPPsqx0xTNhkTI2o3cSxrjrFw3TtuSq7I8enhH8GGwvDs3-8_XcL8_1yStV9wxX8H6ma2Ob5qx4XBCEcCeP_0TdO5fdp8SCwHMx2PW_/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.51.07.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="356" data-original-width="490" height="232" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieMaqG_pSa99n8stlqX-rJyjEfSdi7W1KpBLlv0MPPsqx0xTNhkTI2o3cSxrjrFw3TtuSq7I8enhH8GGwvDs3-8_XcL8_1yStV9wxX8H6ma2Ob5qx4XBCEcCeP_0TdO5fdp8SCwHMx2PW_/s320/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.51.07.png" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisGxa6RGwFV5HD6D1r2UhZPW-HYjDg3AgLlK3oseiAwPC1CdJGKxgRxAZLIcVP1lqobATDXW6FIbQBOiNFi-GoIAXkBDsJDkgqy1GQpp8QprFNnxz5WoFTnyqKJzKFOdk8DhPU69Ya7Gac/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.51.59.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="151" data-original-width="178" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisGxa6RGwFV5HD6D1r2UhZPW-HYjDg3AgLlK3oseiAwPC1CdJGKxgRxAZLIcVP1lqobATDXW6FIbQBOiNFi-GoIAXkBDsJDkgqy1GQpp8QprFNnxz5WoFTnyqKJzKFOdk8DhPU69Ya7Gac/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.51.59.png" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Menlo<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuQl-S4G4H_b3ouhSPeAqyOxLDZEHKd4vQZDJ7sOekIvHmutb8c3acfGt34u9mCBQZPrHi8jtCESWvJQ32-nBrtpGiGTf3ZDU4OVPg9rhiFEo2HkE7vbpZxnJjOaAZuJzyWUyBPzjD6-nI/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.49.57.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="338" data-original-width="492" height="219" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuQl-S4G4H_b3ouhSPeAqyOxLDZEHKd4vQZDJ7sOekIvHmutb8c3acfGt34u9mCBQZPrHi8jtCESWvJQ32-nBrtpGiGTf3ZDU4OVPg9rhiFEo2HkE7vbpZxnJjOaAZuJzyWUyBPzjD6-nI/s320/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.49.57.png" width="320" /></a></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs7SzWYqiUX9a-Xcqhe7zi5kVi7f_ODyzuyxwL6rmS8YQlUPWgZZgYlKdzXqxWMaYFYLQ1sNuAcOGamIOYuPYU9hqQxQYNAnKH9uM68eSfFCESPQU9BHv3iquqfjjy8VCqN7vd-2phRZEG/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.49.27.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="158" data-original-width="198" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs7SzWYqiUX9a-Xcqhe7zi5kVi7f_ODyzuyxwL6rmS8YQlUPWgZZgYlKdzXqxWMaYFYLQ1sNuAcOGamIOYuPYU9hqQxQYNAnKH9uM68eSfFCESPQU9BHv3iquqfjjy8VCqN7vd-2phRZEG/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-11-13+%25E4%25B8%258B%25E5%258D%25882.49.27.png" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-55253707587138915992019-10-31T18:43:00.000-07:002019-10-31T18:43:59.617-07:00[iOS] 文字轉語音如果你想要讓你的App有朗讀的功能,也就是文字轉語音,使用方式非常的簡單。<br />
<div>
<br /></div>
<div>
首先要import AVFoundation,</div>
<div>
<br /></div>
<div>
接著只需要寫以下的程式碼即可。</div>
<div>
<br /></div>
<script src="https://gist.github.com/Aiur3908/f554e527bafcbeec8ec429e6b8a09a54.js"></script>
Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-60469217625580498412019-10-14T22:41:00.005-07:002019-11-20T07:19:11.726-08:00[iOS] Swift some 與 Opaque Result Types Swift5.1之後出現了SwiftUI,學習時發現了一個新的關鍵字<b>some</b>
<br />
<br />
<script src="https://gist.github.com/Aiur3908/6552889e4b99ee10a53ebb9a6de055b6.js"></script>
<br />
因此稍微研究了一下有關some的使用方式。
<br />
<br />
簡單的說當你的Protocol有associatedtype或Self時,Swift無法得知你的具體類型為何。
<br />
<br />
我們先來看一般狀況的Protocol,我們有個Animal的Protocol,並且有兩個struct去實作它。
<br />
<br />
<script src="https://gist.github.com/Aiur3908/e93bf1a38e4f9988f41e1d6a5807c746.js"></script>
此時我們寫一個Func,可以取得一個Animal<br />
<br />
<script src="https://gist.github.com/Aiur3908/0277c56124005f85103523f33162d9a0.js"></script>
一切都很美好,但是如果我們想在Protocol加入associatedtype,像是以下的程式碼。<br />
<br />
<script src="https://gist.github.com/Aiur3908/9764f0539321d4434ec7eac0e181bfcd.js"></script>
接著你會發現原本的取得Animal方法被發出警告訊息<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihR4O5Po65w5Dn6tltv5Qvh2J6BqndItpVMBr9OKEFtEbxpyrRtTYRULgcHiui7Wk7Svd671hND7Q0wfgfVYur65CcUMiR7CbZZHDxrR1xGKRX8FOyWRHIZ-Zn8SwzBOr61zB2axtF8MqI/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258A%25E5%258D%258811.54.36.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="242" data-original-width="1502" height="102" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihR4O5Po65w5Dn6tltv5Qvh2J6BqndItpVMBr9OKEFtEbxpyrRtTYRULgcHiui7Wk7Svd671hND7Q0wfgfVYur65CcUMiR7CbZZHDxrR1xGKRX8FOyWRHIZ-Zn8SwzBOr61zB2axtF8MqI/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258A%25E5%258D%258811.54.36.png" width="640" /></a></div>
原本的做法,你必須改成以下的寫法<br />
<br />
<script src="https://gist.github.com/Aiur3908/61c694fb3a3749b0dacc1f2194b9c0cb.js"></script>
<br />
使用時也必須指定資料型態<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhguiVG-yuhqhG2sE56a4hDcSdEdjxLb15FiY9OPB_iA8WBo82PUDjBVc1jtwl6jQERZoz-j7H7cRM2GzxkT3uibFtCqYpnYP533RKetMqxowM9yYNFFW04pMHCTSYZLPQmdoiVLGAFZUNU/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.19.53.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="146" data-original-width="988" height="94" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhguiVG-yuhqhG2sE56a4hDcSdEdjxLb15FiY9OPB_iA8WBo82PUDjBVc1jtwl6jQERZoz-j7H7cRM2GzxkT3uibFtCqYpnYP533RKetMqxowM9yYNFFW04pMHCTSYZLPQmdoiVLGAFZUNU/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.19.53.png" width="640" /></a></div>
<br />
整體來說並不是太方便,因此多了some關鍵字,我們只需要將原本的程式碼改成以下的樣子<br />
<br />
<script src="https://gist.github.com/Aiur3908/8e9de0463416429b7c57166197778dc7.js"></script>
如此一來就可以很方便的使用,使用時也不必指定資料型態。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRBccg9HOX3rnfh0FTZ8JcKFaOGX4YgdvfaDHVKr6bM-QXVsC9r8FJ3jth0uOHVeOdhBIpcq3vLzWDB0wCQbW2yQ5jUmOu9yF3G3-bkEu5Hr2zvlj-CZhtDePfpdfqJeYJnjj1AxnzyLw4/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.23.56.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="134" data-original-width="744" height="114" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRBccg9HOX3rnfh0FTZ8JcKFaOGX4YgdvfaDHVKr6bM-QXVsC9r8FJ3jth0uOHVeOdhBIpcq3vLzWDB0wCQbW2yQ5jUmOu9yF3G3-bkEu5Hr2zvlj-CZhtDePfpdfqJeYJnjj1AxnzyLw4/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.23.56.png" width="640" /></a></div>
<br />
但是要注意的是,若是你的Func有多種類回傳值,分別是不同的實作該Protocol是不行的。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcdZV8tuPMnOwTUixq5e-iBA6KKEQKrl9GHu3hSlSbttG2NFTx6avmCa2SHTTCVk6M_2N_ctr4KnF8dz96QLpq-5S4NR9UonpCKhoVsvb68jUPXyKH26HTtsrSTf21YNnOCJ89x_Yh_D0b/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.27.16.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="346" data-original-width="1544" height="142" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcdZV8tuPMnOwTUixq5e-iBA6KKEQKrl9GHu3hSlSbttG2NFTx6avmCa2SHTTCVk6M_2N_ctr4KnF8dz96QLpq-5S4NR9UonpCKhoVsvb68jUPXyKH26HTtsrSTf21YNnOCJ89x_Yh_D0b/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.27.16.png" width="640" /></a></div>
<br />
簡單的說some會依照你的回傳值來判斷是哪個類型實作了該Protocol,你不用特別指定哪個類型,而是依照你回傳的值來決定。<br />
<br />
舉一個比較常見的例子,Equatable這個Protocol,它的定義如下。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHgKMoaAFdnQqckST1mUZPr9qH2fPaUAAlcuHkmsQMPshitHtvdf0H4eNOTTIgFhTqCM6cRYZTk5yx2fh-o9FasNz-mV1kVECRVW0JCOFH65C2aayRWnlnZIQ4Sxo0pOiov_nKSvtggcQX/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.31.34.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="532" data-original-width="1158" height="294" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHgKMoaAFdnQqckST1mUZPr9qH2fPaUAAlcuHkmsQMPshitHtvdf0H4eNOTTIgFhTqCM6cRYZTk5yx2fh-o9FasNz-mV1kVECRVW0JCOFH65C2aayRWnlnZIQ4Sxo0pOiov_nKSvtggcQX/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.31.34.png" width="640" /></a></div>
<br />
你必須實作==這個Func才算符合Equatable這個Protocol,我們都知道Int有實作該Protocol,因此我們寫一個Func,來隨機產生一個Int,可是我們希望回傳的資料型態是Equatable。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjh94NO6TePmZXKWunrTffAcOVEYHrSgF-orEkM4xkalyAaRt8AhrLrPkFcxzGE6FCzc30QDko-I6NQcXUyIMq-97sKPmxMgluWTkPgj0_ItDllTqh9Hp2a5q65FZlnfAl9TnmYXCa85TFv/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.33.13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="166" data-original-width="1500" height="70" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjh94NO6TePmZXKWunrTffAcOVEYHrSgF-orEkM4xkalyAaRt8AhrLrPkFcxzGE6FCzc30QDko-I6NQcXUyIMq-97sKPmxMgluWTkPgj0_ItDllTqh9Hp2a5q65FZlnfAl9TnmYXCa85TFv/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.33.13.png" width="640" /></a></div>
<br />
<br />
經過上面的例子我們知道是不行的,因為Equatable裡面有使用到Self,因此必須加上some關鍵字。<br />
<br />
我們加上some之後,我們繼續增加另一個產生字串的Func,一樣回傳Equatable。<br />
<br />
接著我們呼叫這兩個方法,將它們的值取出。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6Pu49fobkBveeAHoFTCZZ50SUDA0oMFCGGsGPMcOGfWuQZ6aGhXH49-0AUdtB14i_lFptuvSzlGidFgrp1RtHeg_PovZXl5E4a1SYPuql70j0a1RqKYrfOrj-w0IPrL3rC8aUUrteIFPR/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.35.54.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="258" data-original-width="848" height="193" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6Pu49fobkBveeAHoFTCZZ50SUDA0oMFCGGsGPMcOGfWuQZ6aGhXH49-0AUdtB14i_lFptuvSzlGidFgrp1RtHeg_PovZXl5E4a1SYPuql70j0a1RqKYrfOrj-w0IPrL3rC8aUUrteIFPR/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.35.54.png" width="640" /></a></div>
<br />
會發現,兩個都是Equatable資料型態,那我們來使用==方法看看。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirpcViMrQdoevl7DjD9vuUUupeCZ7S4fei0rS353VpF77N1sQq6CYWEhL108FPxZ6eUcr8xLatH8mHz6C_ESRZQW-VYeWRcb4bnk8xlop7I6exwcCByLKdcTAgOM4CoVjAXETn2He2gKYJ/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.37.08.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="329" data-original-width="1406" height="148" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirpcViMrQdoevl7DjD9vuUUupeCZ7S4fei0rS353VpF77N1sQq6CYWEhL108FPxZ6eUcr8xLatH8mHz6C_ESRZQW-VYeWRcb4bnk8xlop7I6exwcCByLKdcTAgOM4CoVjAXETn2He2gKYJ/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.37.08.png" width="640" /></a></div>
<br />
事實上是不行的,因為雖然表面上都是Equatable,實際上一個是Int,一個是String,雖然我們看不出來,但是Xcode很聰明的看出差異了。<br />
<br />
但是如果來源都是同一個Func所Return的值,Xcode會視為相同的。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFmisSSuQ4oi5YJtP5Fke-oTabonbbBahWmczayP1UeKYA_VjBMIWQ1X0amfGgsUNUSXj8FBSrdsFIpqhod9cDc9Br-SN8LsNTWK7Mt99GFULD5vyj7ZrtLqEuBLrv1CUYXI3HOfrwxsOW/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.39.18.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="514" data-original-width="784" height="418" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFmisSSuQ4oi5YJtP5Fke-oTabonbbBahWmczayP1UeKYA_VjBMIWQ1X0amfGgsUNUSXj8FBSrdsFIpqhod9cDc9Br-SN8LsNTWK7Mt99GFULD5vyj7ZrtLqEuBLrv1CUYXI3HOfrwxsOW/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.39.18.png" width="640" /></a></div>
<br />
如果你有兩個Func所Return的值是相同的,Xcode也會認為不同哦,它只認Func,不認回傳值。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGgigyUZbgW_AntkVzNk_07PFq9Nx9Ck86Jvxm3x0l6qt0Dv_z4sABFynluNKmFcz2MHjQZG21VqSgJTP-MKB3HXNzvHHDlTKxNCsAAHXwbe0de2MPyPPNoc941MZRpLhwtAxXnmO9YfMc/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.41.27.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1558" height="294" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGgigyUZbgW_AntkVzNk_07PFq9Nx9Ck86Jvxm3x0l6qt0Dv_z4sABFynluNKmFcz2MHjQZG21VqSgJTP-MKB3HXNzvHHDlTKxNCsAAHXwbe0de2MPyPPNoc941MZRpLhwtAxXnmO9YfMc/s640/%25E6%2588%25AA%25E5%259C%2596+2019-10-15+%25E4%25B8%258B%25E5%258D%25881.41.27.png" width="640" /></a></div>
<br />Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-26295874007763017252019-09-09T20:35:00.001-07:002019-09-09T20:40:15.056-07:00[iOS] UITableView - 基礎2透過基礎1中我們學會了如何使用UITableView。<br />
<br />
若是還沒看基礎1,可以透過以下連結前往<br />
<br />
<h2>
<a href="https://aiur3908.blogspot.com/2019/09/ios-uitableview.html">基礎1</a></h2>
<div>
<br /></div>
<div>
接下來我們可以使用UITableViewDelegate來取得使用者點選了哪個Cell。</div>
<div>
<br /></div>
<div>
我們先建立簡單的UITableView,可以透過基礎1的結果繼續往下做。</div>
<div>
<br /></div>
<div>
接著在我們的ViewController,透過extension來實作UITableViewDelegate</div>
<br />
<script src="https://gist.github.com/Aiur3908/e630084080b5b18c3f5752264e9f4b83.js"></script><br />
<br />
此時你會發現Xcode並沒有任何變化,因為UITableViewDelegate這個Protocol,所有的func都是可選的,因此就算你一個func都沒有實作,它也認為你已經實作了此Procotol。<br />
<br />
但是我們會需要知道使用者點選了哪個Cell,我們可以在Xcode輸入以下的文字<br />
<br />
tableviewdid<br />
<br />
接著靠Xcode的自動完成功能,選擇我們所需要的func<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRErHhXCwxQKzw8XZDvHDfvOhT-48Im1U4XMmJx1qqhkCKCvjH9z_3DmofBs0dWqctTTRMVVz4AoCJmiifsGr39aBito4GCFEVPmCnvzc-vlc9bjY7zqme2D5SatJpsT5MxW-DSz6D-GgD/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-09-10+%25E4%25B8%258A%25E5%258D%258811.29.29.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="91" data-original-width="1014" height="57" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRErHhXCwxQKzw8XZDvHDfvOhT-48Im1U4XMmJx1qqhkCKCvjH9z_3DmofBs0dWqctTTRMVVz4AoCJmiifsGr39aBito4GCFEVPmCnvzc-vlc9bjY7zqme2D5SatJpsT5MxW-DSz6D-GgD/s640/%25E6%2588%25AA%25E5%259C%2596+2019-09-10+%25E4%25B8%258A%25E5%258D%258811.29.29.png" width="640" /></a></div>
<br />
<b>tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)</b><br />
<b><br /></b>
為UITableViewDelegate Protocol的其中一個func,當使用者點選了任何一個Cell時,將會觸發,會回傳兩個值,分別是你所點選的tableView是何者,以及所點選的indexPath,接著我們將func寫入以下程式碼,使用者點選時會印製log出來。<br />
<br />
<script src="https://gist.github.com/Aiur3908/c33b45decabeea12b7cfc69e6052d997.js"></script><br />
<br />
最後不要忘記在viewDidLoad指定delegate 哦,以下為完整程式碼。<br />
<br />
<script src="https://gist.github.com/Aiur3908/785e7a87848337f09e78d73c06b1de7a.js"></script><br />
<br />
你可以試著執行看看程式,點選其中一個Cell的時候,應該會有訊息印製出來哦。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwy9F7TLsbqHWDvcTIPgMgcpj28GTMrDi2BV1Lx8sg8ceV__PuDjck1fp399hY1HWASJoD3EcrnjdPvQgVQSiPYBrejlFiKYBUZ9A-tk0auZRlsjD4tUQKmG7uIrHDu48HqKMT2qqr-Wmg/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-09-10+%25E4%25B8%258A%25E5%258D%258811.35.25.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="791" data-original-width="674" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwy9F7TLsbqHWDvcTIPgMgcpj28GTMrDi2BV1Lx8sg8ceV__PuDjck1fp399hY1HWASJoD3EcrnjdPvQgVQSiPYBrejlFiKYBUZ9A-tk0auZRlsjD4tUQKmG7uIrHDu48HqKMT2qqr-Wmg/s640/%25E6%2588%25AA%25E5%259C%2596+2019-09-10+%25E4%25B8%258A%25E5%258D%258811.35.25.png" width="544" /></a></div>
<br />Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-33034871767965274162019-09-09T01:16:00.003-07:002019-09-09T20:40:04.407-07:00[iOS] UITableView - 基礎1UITableView,是一種表格化顯示的View,可以從各式各樣的App當中看見它的身影,是十分常見的一種View。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr9oFmwTH2M8G4hg4bRGZYiB1W9w4v0QUXmPMTwa7inDjsv5eUQjJlS3Tj6OIh5eqPMi5RQwJXQRrK4YZd-tpNL2PjAQxDDkoYH8FCcXCHoDSRkcsMl5W9q0oEomd4YBJM49Br4q3BJ3pA/s1600/1eb44f8d-1907-4949-9208-f2fb7f3ffd1b.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1022" data-original-width="1194" height="546" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr9oFmwTH2M8G4hg4bRGZYiB1W9w4v0QUXmPMTwa7inDjsv5eUQjJlS3Tj6OIh5eqPMi5RQwJXQRrK4YZd-tpNL2PjAQxDDkoYH8FCcXCHoDSRkcsMl5W9q0oEomd4YBJM49Br4q3BJ3pA/s640/1eb44f8d-1907-4949-9208-f2fb7f3ffd1b.png" width="640" /></a></div>
這邊來介紹最基本的使用方式,首先先開啟一個新的專案,並且於StoryBoard中,加入UITableView,並且設置簡單的Constraint,將UITableView佔滿UIViewController。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh95PH2DWykDAE94rZ8FEA-vpjKHVaFpmXePiXwqxujKoFlY8j3isdRdngbp7OFBuT2P36okKCgxvPmD5ZZCZSG935XOucWjfhIz7bGpiGzXMWdJxNV44sehHK9g67kDYqZZOpA0QRSq2n4/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25883.53.13.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1029" data-original-width="571" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh95PH2DWykDAE94rZ8FEA-vpjKHVaFpmXePiXwqxujKoFlY8j3isdRdngbp7OFBuT2P36okKCgxvPmD5ZZCZSG935XOucWjfhIz7bGpiGzXMWdJxNV44sehHK9g67kDYqZZOpA0QRSq2n4/s640/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25883.53.13.png" width="354" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
接著,我們建置IBoutlet,將UITableView與我們的UIViewController class做關聯,以下我們命名為tableView。</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<script src="https://gist.github.com/Aiur3908/a3ac914493ee3db644371cfab9e62d8d.js"></script>
<br />
<div class="separator" style="clear: both; text-align: left;">
下一步,如果要使用UITableView,我們必須實作UITableViewDataSource這個Protocol。</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
因此我們加入extension,讓我們的ViewController去實作UITableViewDataSource,此時你會發現Xcode自動發出警告,若是要實作這個Protocol,必須實作一些方法</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLay-P2scAiYeF4_50q2gHwP6XL1ydz8qnaez0L_LQ_5mtaqdn2FGV_cbrtBESQ9AFih_JauvQBKuamvG3hzD8cVOUtUJdprIKsFkQDSKtGXc0UqIeuR43VP_6PNSq7Hb72ph8-ZV5gHBD/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25883.59.52.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="161" data-original-width="1051" height="98" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLay-P2scAiYeF4_50q2gHwP6XL1ydz8qnaez0L_LQ_5mtaqdn2FGV_cbrtBESQ9AFih_JauvQBKuamvG3hzD8cVOUtUJdprIKsFkQDSKtGXc0UqIeuR43VP_6PNSq7Hb72ph8-ZV5gHBD/s640/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25883.59.52.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
按下Fix後,XCode會自動幫你產生所需要的程式碼。</div>
<br />
<script src="https://gist.github.com/Aiur3908/0c298adb2bd996a0751dc2750ac2dca4.js"></script>
必須要實作兩個方法。<br />
<br />
<b>tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int</b><br />
<br />
你必須告訴tableView,你要顯示幾個Row<br />
<br />
<b>tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell</b><br />
<b><br /></b>
你必須告訴tableView,每個Row所顯示的Cell<br />
<br />
接著我們先切回StoryBoard,並且搜尋UITableViewCell,將UITableViewCell拖曳到UITableView裡面。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz7tz6dJCNpsJYefYg37SJNWP35yeQVFZa8tqr2y0Z7_kClWkzqjw9BPKY5TM8TrociU2qbpBzZ09CNhVgWhjJkuscUd7lDMhgJ601HEqHZSHLSfioZJHS8nI2zI0ToyZ1vgPk4DHEeBbe/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25884.06.05.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1113" data-original-width="1068" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz7tz6dJCNpsJYefYg37SJNWP35yeQVFZa8tqr2y0Z7_kClWkzqjw9BPKY5TM8TrociU2qbpBzZ09CNhVgWhjJkuscUd7lDMhgJ601HEqHZSHLSfioZJHS8nI2zI0ToyZ1vgPk4DHEeBbe/s640/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25884.06.05.png" width="614" /></a></div>
<br />
接著我們選擇這個Cell,然後於右邊的屬性配置區,輸入這個Cell的Identifier,我們將它命名成『MyCell』。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM5Mwx7m76FGPS3nQKMlD6RvKDWvyHpcKuwR28jtjImo-fqFNhpujyO25IGBTHlymM2qgHU_mKnR8Yw8zYc1UcLe-i25zVmbFNBEdx3cu4C4dwo1HbeZMXClXnd2pEVCTDlkb8yWiC-xZ0/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25884.08.25.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="309" data-original-width="628" height="314" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM5Mwx7m76FGPS3nQKMlD6RvKDWvyHpcKuwR28jtjImo-fqFNhpujyO25IGBTHlymM2qgHU_mKnR8Yw8zYc1UcLe-i25zVmbFNBEdx3cu4C4dwo1HbeZMXClXnd2pEVCTDlkb8yWiC-xZ0/s640/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25884.08.25.png" width="640" /></a></div>
<br />
下一步我們可以回到程式碼,將不足的部分補齊,首先我們告訴TableView,我們需要10個Row。<br />
<br />
<script src="https://gist.github.com/Aiur3908/28ed317417466edff2109f69e23e1612.js"></script>
接著我們將下一個程式碼也補齊,我們透過剛才於Storyboard設置的Identifier來取得Cell,並且設置顯示的文字。<br />
<br />
<script src="https://gist.github.com/Aiur3908/f77b7058913f336e8aff584014a80e14.js"></script>
最後於viewDidLoad,將tableView的dataSource設置為我們的ViewController,以下是完整的程式碼。<br />
<br />
<script src="https://gist.github.com/Aiur3908/e548e20d6a72c4398a2788691088a0f3.js"></script>
以及執行結果。<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEmlT4Tp_fTMXfNU1Pf-eHLhVC1Fj95anBVDp3B9_qbg0TNJhVpfZZafomuf08KZtIGCADV_sGKQGXddZbdrdZQxgvYEnde8xHQrzH99VTLZV823wtclzWiriu7daZ8u_lyz_c40Yvd32f/s1600/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25884.15.51.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="802" data-original-width="442" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEmlT4Tp_fTMXfNU1Pf-eHLhVC1Fj95anBVDp3B9_qbg0TNJhVpfZZafomuf08KZtIGCADV_sGKQGXddZbdrdZQxgvYEnde8xHQrzH99VTLZV823wtclzWiriu7daZ8u_lyz_c40Yvd32f/s640/%25E6%2588%25AA%25E5%259C%2596+2019-09-09+%25E4%25B8%258B%25E5%258D%25884.15.51.png" width="352" /></a></div>
<br />
以上就是TableView,最基本的用法,要使用就必須實作UITableViewDataSource這個Protocol。<br />
<br />
接下來可以看基礎2學習如何使用UITableViewDelegate來捕捉使用者點選了哪個Cell哦。<br />
<br />
<h2>
<a href="https://aiur3908.blogspot.com/2019/09/ios-uitableview-2.html">基礎2</a></h2>
Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-83036544539814470812019-08-30T02:29:00.001-07:002019-08-30T02:51:11.520-07:00[iOS] PropertyWrapper屬性包裝器PropertyWrapper,屬性包裝器,透過屬性包裝器,來針對屬性進行包裝。<br />
<br />
舉例來說,我們希望某個變數它永遠都是大寫。<br />
<br />
<script src="https://gist.github.com/Aiur3908/9e353b0a29cfbcb72a4bf85a8cf78041.js"></script><br />
我們可以在使用的時候再將它轉換,可是感覺有些麻煩,因此我們可能會寫成這樣<br />
<br />
<script src="https://gist.github.com/Aiur3908/4e3893b6c00c25d70cbe6354675d8dc3.js"></script><br />
但是這樣寫初始化的時候並不會進入didSet,因此只能很勤勞的在建構子也加入轉換大寫的程式碼。<br />
<br />
<script src="https://gist.github.com/Aiur3908/7195cbc9d519bfbd7ed1994a94c056be.js"></script><br />
終於大功告成了,但總的來說並不夠美觀,因為如果有更多的屬性,那不就要在每個屬性的didSet,與建構子中加入程式碼,此時,屬性包裝器就可以派上用場了。<br />
<br />
我們建立一個Struct,命名成Uppercased,並在它的上方加入@propertyWrapper關鍵字。<br />
<br />
接著Xcode會提示說,propertyWrapper需要有一個名為wrappedValue的屬性,我們將這個屬性加入,並且做一些處理。<br />
<br />
<script src="https://gist.github.com/Aiur3908/9b95d002e44c2294999253eeb3c724d8.js"></script><br />
程式碼做的事情就是將wrappedValue在set的時候轉換成大寫存在value變數之中,get的時候就取出轉換成大寫的value變數,基本上跟上方獨立處理是差不多的,但是這時候神奇的事情發生了,我們回到Data結構裡面,把title前方加入@Uppercased來修飾。<br />
<br />
<br />
<script src="https://gist.github.com/Aiur3908/c6ab28176f5a0746ad8a8dbc12ee7c76.js"></script><br />
這樣這個title就被我們自定義的屬性包裝器包裝過了,此時要存取這個屬性都會透過包裝器來存取,就永遠都是大寫了。<br />
<br />
有一個例子我覺得還不錯,存取UserDefault就可以使用屬性包裝器。<br />
<br />
<script src="https://gist.github.com/Aiur3908/abe738a8ca777475fcdbbd9706c94ca6.js"></script>
<br />
存取的時候透過屬性包裝器直接存入到UserDefault之中,就可以不需要寫一堆重複的程式碼了。Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-26695000021883495282019-07-03T22:27:00.005-07:002019-07-03T22:27:38.038-07:00[iOS] Float轉換成Double時,會有些許的誤差有時候我們可能會把Float轉換成Double。<br />
<div>
<br /></div>
<div>
像是使用UISlider時,將它的Value取出後,轉換成Double。</div>
<div>
<br /></div>
<div>
但是要特別小心此問題,轉換的時候,會有精度上的誤差,</div>
<div>
<br /></div>
<div>
舉例來說,以下的程式碼的結果可能會跟你想像的不太一樣。</div>
<div>
<br />
<script src="https://gist.github.com/Aiur3908/6c8f4bbc2c105e31e5653dbc593ed8e4.js"></script>
因為Float的精度與Double的不一樣,即使小數點只有幾位的情況下,<br />
<br />
轉換過去也是有可能有精度上的誤差。<br />
<br />
因此使用時必須特別小心。</div>
Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-29588445112696112422019-05-07T19:28:00.000-07:002019-05-07T19:28:04.025-07:00[iOS] 一次改調整個專案Storyboard or Xib設定的顏色有時後顏色會直接用Storyboard或xib來做設定,<br />
<br />
可是遇到要更換顏色的時候有些麻煩,必須每個檔案都打開來看。<br />
<br />
所以寫了以下的小工具,可以一口氣改掉整個專案的某個顏色<br />
<br />
<a href="https://github.com/Aiur3908/XibChangeColor">https://github.com/Aiur3908/XibChangeColor</a><br />
<br />
下載後用文字編輯器開啟XibChangeColor,<br />
<br />
並輸入要修改的顏色RGBA,<br />
<br />
顏色對應的小數點盡量不要輸入太多,因為同一個顏色Xcode產生出來的小數點有些許誤差,因此輸入太完整,有可能沒取代到。<br />
<br />
將XibChangeColor放入到專案目錄中,並且開啟終端機前往該目錄。<br />
<br />
執行XibChangeColor,即可修改顏色:DAiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-50753433465428207002019-01-06T22:50:00.002-08:002019-10-31T19:25:29.765-07:00[iOS] 利用UIImagePickerController 取得相簿內照片有時候可能會需要取得使用者手機內的照片,這時候就可以使用UIImagePickerController來取得。<br />
<br />
假設是從使用者的相片庫取得,可以參考以下的程式碼。<br />
<br />
<br />
<script src="https://gist.github.com/Aiur3908/0c274a43b88cc8c9bfc63815d852e322.js"></script><br />
接著要實作兩個Protocol,來符合UIImagePickerController的Delegate。<br />
<br />
<script src="https://gist.github.com/Aiur3908/254de07b433a8986187410c956ae9f42.js"></script><br />
如此一來就可以完成一個簡單的取用使用者照片的程式。<br />
<br />
如果你想要從使用者的相機取得照片,可以參考以下的程式碼。<br />
<br />
<br />
<script src="https://gist.github.com/Aiur3908/1e49c5c7042b207cdf6398d93d4e9a68.js"></script><br />
記得要將Privacy - Camera Usage Description加入到Info.plist裡面哦<br />
<br />
<br />Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-38237635953163558902018-06-26T23:11:00.000-07:002018-06-26T23:11:00.061-07:00[iOS] Singleton的產生語法有時候整個App生命週期可能需要某幾個只有一個實體的Class,<br />
<div>
<br /></div>
<div>
這時候可以使用Singleton來達成,以下是產生Singleton的程式碼。</div>
<div>
<br />
Swift</div>
<div>
<br /></div>
<script src="https://gist.github.com/Aiur3908/f3a02daa16dd3dcb4eb17e5e57104110.js"></script><br />
<div>
Objective - C<br />
<br />
<script src="https://gist.github.com/Aiur3908/1ebacac0c8415376a2a316d5c1d59667.js"></script><br />
<br /></div>
Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-59145567458349328242018-06-14T00:47:00.001-07:002018-06-14T00:49:28.216-07:00[iOS] 利用xib來製作客製化View<span style="color: red;">圖片能點擊放大</span><br />
<br />
1. 新增一個客製化的View,命名成為你需要的名稱,且繼承於UIView<br />
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZbTIUTUBW73bY5VxyxmqAM0insojS23rsFI9CijMEQvboiXUMj-rSGmovCpY1JYt4dX_g7Ltdqzq08GpfvCNZ1VILmw1Bedk4xVlzXuTZ5g2EMIE1QZOyMl-hDpf0dsO6ozofiv5h724b/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.18.50.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1054" data-original-width="1460" height="462" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZbTIUTUBW73bY5VxyxmqAM0insojS23rsFI9CijMEQvboiXUMj-rSGmovCpY1JYt4dX_g7Ltdqzq08GpfvCNZ1VILmw1Bedk4xVlzXuTZ5g2EMIE1QZOyMl-hDpf0dsO6ozofiv5h724b/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.18.50.png" width="640" /></a></div>
<div>
<br /></div>
<div>
2.新增一個同名的xib,此時你的專案應該會有兩個檔案</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggMqmh2HUFmhKfffy9jaNSCxLWvZ76aYSWag4Cmg4wg2HVK6kaSzs17eHBo_7DQwSLfChEiyrXlrPHvPJN3H6SZvWmuKtimQl8XWhVp-DyYIFImRpdKAnNqM3TeJVvidWcz03SJHuqcjpO/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.30.36.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="88" data-original-width="486" height="57" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggMqmh2HUFmhKfffy9jaNSCxLWvZ76aYSWag4Cmg4wg2HVK6kaSzs17eHBo_7DQwSLfChEiyrXlrPHvPJN3H6SZvWmuKtimQl8XWhVp-DyYIFImRpdKAnNqM3TeJVvidWcz03SJHuqcjpO/s320/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.30.36.png" width="320" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
3. 開始設計你的View,這邊簡單的放入一個Button,並且改為綠色</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibiYIs8mRptcVjuIAx89l6ft2bgGKNJ85llCcMlmoAstlrI7FomgpmuYqGzGkqQxDurIa9uiHBjYxahFxrJvzfwizvRQwGHyxsV4MXzNJTSs9Dk_oxNeg60EZoKcxuNe5wd8gvPyMzRZIs/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.32.06.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="718" data-original-width="1502" height="304" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibiYIs8mRptcVjuIAx89l6ft2bgGKNJ85llCcMlmoAstlrI7FomgpmuYqGzGkqQxDurIa9uiHBjYxahFxrJvzfwizvRQwGHyxsV4MXzNJTSs9Dk_oxNeg60EZoKcxuNe5wd8gvPyMzRZIs/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.32.06.png" width="640" /></a></div>
<div>
<br /></div>
<div>
4. 點選上方的File's Owner類別後,將右邊的Custom Class設置為你的Class名稱。</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2W4w9sTWjzL9tdJR3bpAtqOWO7Jx7uk979r-nSELf5SsnrWcHyjVXR4U_BwdS67WYPlF0AjJUhbEgXZwSEtrgfbAgxb1YvB0-uKxsK4RiHH2A2x47fc2ArQx7__vftT9spmQhBCObKUjl/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.32.54.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="626" data-original-width="1600" height="249" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2W4w9sTWjzL9tdJR3bpAtqOWO7Jx7uk979r-nSELf5SsnrWcHyjVXR4U_BwdS67WYPlF0AjJUhbEgXZwSEtrgfbAgxb1YvB0-uKxsK4RiHH2A2x47fc2ArQx7__vftT9spmQhBCObKUjl/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.32.54.png" width="640" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
5.此時你應該可以加入IBoutlet與IBAction了,我們加入一個IBAction,在Touch Up Inside時會印出Log。</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW9Pn9h28GcQzZ1P4iQK_vAfFHnJVTMe-YyddABXJW3p1n0aGOrbvuY4v_aiFccXjB6dZVDXIIYY0_G-KnodlGS2JHkdT_bdo13pdmTehfOkpX2Toz6Bjcew-NAytCPj5pFL_zol6Cq22s/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.36.03.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="326" data-original-width="1154" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW9Pn9h28GcQzZ1P4iQK_vAfFHnJVTMe-YyddABXJW3p1n0aGOrbvuY4v_aiFccXjB6dZVDXIIYY0_G-KnodlGS2JHkdT_bdo13pdmTehfOkpX2Toz6Bjcew-NAytCPj5pFL_zol6Cq22s/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.36.03.png" width="640" /></a></div>
<div>
<br /></div>
<div>
6. 此時你的程式碼應該只有這樣</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDjtZQpMMQ9Y-OvN9QiLA0y8W5VPMv8EjyBwVZ6u1LlFl3mT7Mzxtjhpzq_kOixZw22AYB4V8SQMGU4SlsYJw1xyWnDucIJSKOhFA4PdziMlamBgBt-17MpG-fVci7EVjMSIngOI40wM8d/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.36.47.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="404" data-original-width="1274" height="202" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDjtZQpMMQ9Y-OvN9QiLA0y8W5VPMv8EjyBwVZ6u1LlFl3mT7Mzxtjhpzq_kOixZw22AYB4V8SQMGU4SlsYJw1xyWnDucIJSKOhFA4PdziMlamBgBt-17MpG-fVci7EVjMSIngOI40wM8d/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.36.47.png" width="640" /></a></div>
<div>
<br /></div>
<div>
7. 接著我們要override兩個事件,init(frame: CGRect)以及init?(coder aDecoder: NSCoder),此時你的程式碼應該如下。</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmOr34ycklKSJVZ-Jq41q-xpQmAyVvIN4bTMd5MAnsvLt8ymHzxAIwuaZoEx3mxYtIO8-kLSau0KSMgjZE78E_Peax7pw6ez5-Bti6tcxB9vRGhIxnGiy0Ph5_iq-yY6mY9V6TTUTS6iQn/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.38.42.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="756" data-original-width="1130" height="428" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmOr34ycklKSJVZ-Jq41q-xpQmAyVvIN4bTMd5MAnsvLt8ymHzxAIwuaZoEx3mxYtIO8-kLSau0KSMgjZE78E_Peax7pw6ez5-Bti6tcxB9vRGhIxnGiy0Ph5_iq-yY6mY9V6TTUTS6iQn/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.38.42.png" width="640" /></a></div>
<div>
<br /></div>
<div>
8. 增加一個loadXib的方法,並填入以下的程式碼</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMUwkFgRUPVReEzx0hbkOu0P-jePJDwRaiVbGJq4Eaz7wEvkhq_M4atdwrVppLxnRJC7BGUwFFg6zhkSEOSuaBsve5N6NBQ7KZPj-SwdqICOZcNiT5sR2Mc6qCuoTX28lPffpbWYk4hlLM/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.39.52.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="563" data-original-width="1600" height="224" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMUwkFgRUPVReEzx0hbkOu0P-jePJDwRaiVbGJq4Eaz7wEvkhq_M4atdwrVppLxnRJC7BGUwFFg6zhkSEOSuaBsve5N6NBQ7KZPj-SwdqICOZcNiT5sR2Mc6qCuoTX28lPffpbWYk4hlLM/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.39.52.png" width="640" /></a></div>
<div>
<br /></div>
<div>
這邊主要是使用nib載入xib的View,並加入到這個Class的View,在設置Autolayout讓畫面呈現。</div>
<div>
<br /></div>
<div>
將loadXib方法加入到剛才override的事件之中,此時完整程式碼應該如下。</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<script src="https://gist.github.com/Aiur3908/5468d4585b190e518238940fbd3a01a6.js"></script></div>
<div>
<br />
如此一來,你就能正常使用這個客製化View了。<br />
<br /></div>
<div>
可以直接在StoryBoard上面,加入一個View,並將Class設置為你的客製化View<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQWJLbESRgEqTCtYnGAN7y50pSJZVF90NbnG812r4dNcMf7QhzYnlnBN0pEWfVS29o42GDX9aDjgiBNzGdARA-DGb3Wz5QoTcNTJaNJw_qD3L4FR0NKAGVA-yClA_D6Tr4db529iLLZH3T/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.44.00.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="465" data-original-width="1600" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQWJLbESRgEqTCtYnGAN7y50pSJZVF90NbnG812r4dNcMf7QhzYnlnBN0pEWfVS29o42GDX9aDjgiBNzGdARA-DGb3Wz5QoTcNTJaNJw_qD3L4FR0NKAGVA-yClA_D6Tr4db529iLLZH3T/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.44.00.png" width="640" /></a></div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</div>
<div>
當然,你也可以使用Code產生這個View後在加入到當前頁面上。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQztnvGp4iAVQBLsmw2bx3gIdveZczJ9LJNna5DQ21_MEdaL4OqRM1pPWqTfia4UaP-FljwJ9T4FxU-vasZJoaejNcpIVfvYhy1aWst_yZcyA_D4QOasVNxSSt30qwif5aOntRoYXkvYPn/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.47.26.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="233" data-original-width="1600" height="92" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQztnvGp4iAVQBLsmw2bx3gIdveZczJ9LJNna5DQ21_MEdaL4OqRM1pPWqTfia4UaP-FljwJ9T4FxU-vasZJoaejNcpIVfvYhy1aWst_yZcyA_D4QOasVNxSSt30qwif5aOntRoYXkvYPn/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-06-14+%25E4%25B8%258B%25E5%258D%25883.47.26.png" width="640" /></a></div>
<br /></div>
Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0tag:blogger.com,1999:blog-9157958819417143615.post-62054850383680389072018-04-12T23:26:00.001-07:002018-04-12T23:26:18.290-07:00[Xcode] 中斷點沒有作用的幾個可能性有時候會遇到中斷點沒有作用,可以確認以下幾個點,也許是不小心改到設定了。<br />
<br />
1.關閉中斷點,中斷點變成灰色的。<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCblrj-DAybOMtcnTbYOJLpihEeH__TytAtKo18ytDcOz5wtrYytOCLXRbs-ytXPrUuLaJKH_fpUcZ9OutmD3GMPsM2jZSG2bLlgsjRWE6bXsvg-8D9LtpxP42WO3bLHyRkYX_-RxZnzax/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.06.08.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1030" data-original-width="1334" height="494" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCblrj-DAybOMtcnTbYOJLpihEeH__TytAtKo18ytDcOz5wtrYytOCLXRbs-ytXPrUuLaJKH_fpUcZ9OutmD3GMPsM2jZSG2bLlgsjRWE6bXsvg-8D9LtpxP42WO3bLHyRkYX_-RxZnzax/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.06.08.png" width="640" /></a></div>
<br />
需要點選下面的箭頭讓它變回藍色<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7tiSXR-qNuPXkHbelYwCC7g74g4TqGwS_beWIXqNDeF9cz0S1Wp5fUD3L5qinNxaJ6dbuYSczR77fbO54ayjWvz7-veSgEfj1LG4bbNZSEkR6pf4hBTp_ulDjLvRvoJy5Cgpe-wSPhIQJ/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.07.30.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1036" data-original-width="1272" height="520" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7tiSXR-qNuPXkHbelYwCC7g74g4TqGwS_beWIXqNDeF9cz0S1Wp5fUD3L5qinNxaJ6dbuYSczR77fbO54ayjWvz7-veSgEfj1LG4bbNZSEkR6pf4hBTp_ulDjLvRvoJy5Cgpe-wSPhIQJ/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.07.30.png" width="640" /></a></div>
<br />
2.Scheme中的Debug executable需要被勾選才能正常運作<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJbu_-7zgraB7KWu_KbDU6yKLy7TLfusIJS9FGUrFasmiuiYqzaJsIwdSzRDwPJNh903nMrVllh4De2wcPRtCTfk-7o7Cms_Fsld5OS9neU7ziZxMz6UhvcpLCjfb3ZEJAgCYj0xGShmc5/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.19.39.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="666" data-original-width="1600" height="265" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJbu_-7zgraB7KWu_KbDU6yKLy7TLfusIJS9FGUrFasmiuiYqzaJsIwdSzRDwPJNh903nMrVllh4De2wcPRtCTfk-7o7Cms_Fsld5OS9neU7ziZxMz6UhvcpLCjfb3ZEJAgCYj0xGShmc5/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.19.39.png" width="640" /></a></div>
<br />
3.<span style="background-color: white; color: #555555; font-family: "microsoft yahei"; font-size: 15px; text-align: justify;"> Generate Debug Symbols要設定為YES</span><br />
<span style="background-color: white; color: #555555; font-family: "microsoft yahei"; font-size: 15px; text-align: justify;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLfIb2ZYfxFCdjJs9tMavIy2xuHrKrM-3VY29ZaRU1erSMlehc4dDJF6V4qJvtPa1HqCWHmbTIIFeQ9iEVf4sz1Q4ISgUK8hzI1amRd5-Nbipo7HazDFtE9A1yptEM8qW5SxGGEH2Q50b7/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.23.31.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="418" data-original-width="1506" height="176" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLfIb2ZYfxFCdjJs9tMavIy2xuHrKrM-3VY29ZaRU1erSMlehc4dDJF6V4qJvtPa1HqCWHmbTIIFeQ9iEVf4sz1Q4ISgUK8hzI1amRd5-Nbipo7HazDFtE9A1yptEM8qW5SxGGEH2Q50b7/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.23.31.png" width="640" /></a></div>
<span style="background-color: white; color: #555555; font-family: "microsoft yahei"; font-size: 15px; text-align: justify;"><br /></span>
4.Deployment Postprocessing要設定為NO<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeTWFOF1rNDW2kFMy5ovc2nxrXnL9Eoz5tzTtSz4T5fWxUe2p6QAIu11DDsEKQQoEcfNZGpmRn3E3DBgtXpDBaVtK0nXm7BYklDoQqTwTqh3XzyFAhHOM4UQwXtwMF5P4bC6RsQ0BjkX1w/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.25.11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="512" data-original-width="1512" height="216" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeTWFOF1rNDW2kFMy5ovc2nxrXnL9Eoz5tzTtSz4T5fWxUe2p6QAIu11DDsEKQQoEcfNZGpmRn3E3DBgtXpDBaVtK0nXm7BYklDoQqTwTqh3XzyFAhHOM4UQwXtwMF5P4bC6RsQ0BjkX1w/s640/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2018-04-13+%25E4%25B8%258B%25E5%258D%25882.25.11.png" width="640" /></a></div>
<br />Aiur3908http://www.blogger.com/profile/12698152345605448550noreply@blogger.com0