<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 朱家成 on Medium]]></title>
        <description><![CDATA[Stories by 朱家成 on Medium]]></description>
        <link>https://medium.com/@b0209101?source=rss-3a98f40e510c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dETlmDXAeHbvH8G12R23Pw.jpeg</url>
            <title>Stories by 朱家成 on Medium</title>
            <link>https://medium.com/@b0209101?source=rss-3a98f40e510c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:59:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@b0209101/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[使用apple Music API 製作音樂軟體]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E4%BD%BF%E7%94%A8apple-music-api-%E8%A3%BD%E4%BD%9C%E9%9F%B3%E6%A8%82%E8%BB%9F%E9%AB%94-ba313478c791?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba313478c791</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Wed, 20 Apr 2022 13:35:38 GMT</pubDate>
            <atom:updated>2022-04-21T06:16:53.267Z</atom:updated>
            <content:encoded><![CDATA[<p>今天使用api及解析Json字串的作業</p><p>api網址:<a href="https://itunes.apple.com/search?term=\(singer)&amp;media=music&amp;country=tw">https://itunes.apple.com/search?term=who&amp;media=music&amp;country=tw</a><br>(who=歌手)</p><p>已IU為例</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*zw7xX4Pm1bjWPYvN8c2NEg.png" /></figure><p>從這邊可得到API回傳的JSON格式</p><p>trackName 是歌名<br>artworkUrl100 是圖片<br>previewUrl是音檔</p><p>所以我的model需建立與Json的欄位名稱一樣</p><pre>import Foundation</pre><pre>//Json 大分類<br>struct SearchResponse: Codable {<br>    let resultCount : Int<br>    let results: [StoreItem]<br>}</pre><pre>//Json 小分類,名稱需要與Json一樣<br>struct StoreItem: Codable {<br>    let artistName: String<br>    let trackName: String<br>    let collectionName: String?<br>    let previewUrl: URL<br>    let artworkUrl100: URL<br>    let trackPrice: Double?<br>    let releaseDate: Date<br>    let isStreamable: Bool?<br>    <br>    var artworkUrl500: URL {<br>        <br>        artworkUrl100.deletingLastPathComponent().appendingPathComponent(&quot;500x500bb.jpg&quot;)<br>        <br>    }<br>}</pre><p>前2個畫面</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*N7l7x-2XFIqfRlIv7Ci0Sw.png" /><figcaption>輸入歌手名稱至輸入匡</figcaption></figure><ol><li>所以這部分會抓取textField的值</li><li>丟到API網址內湊成一個完整的API網址</li><li>使用API串回JSON格式</li><li>重整頁面</li></ol><pre>func getAPIData(){<br>        //api網址<br>        let urlString: String = &quot;<a href="https://itunes.apple.com/search?term=\(singer)&amp;media=music&amp;country=tw">https://itunes.apple.com/search?term=\(singer)&amp;media=music&amp;country=tw</a>&quot;<br>        <br>        if let url = URL(string: urlString) {<br>            <br>            URLSession.shared.dataTask(with: url) { data, response , error in<br>                if let data = data {<br>                    //解析Json格式<br>                    let decoder = JSONDecoder()<br>                    decoder.dateDecodingStrategy = .iso8601<br>                    do {<br>                        let searchResponse = try decoder.decode(SearchResponse.self, from: data)<br>                        self.items = searchResponse.results<br>                        DispatchQueue.main.async {<br>                            self.tableView.reloadData()<br>                        }<br>                        <br>                    } catch {<br>                        // show error<br>                    }<br>                } else {<br>                    // show error<br>                }<br>            }.resume()<br>        }<br>    }</pre><p>cell的內容</p><ol><li>cell筆數為API回傳的筆數</li><li>把回傳的內容顯示到畫面上</li></ol><pre>//cell 筆數<br>    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {<br>        // #warning Incomplete implementation, return the number of rows<br>        return items.count<br>    }</pre><pre>//cell內容<br>    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {<br>        let cell = tableView.dequeueReusableCell(withIdentifier: &quot;SongListViewCell&quot;, for: indexPath) as! MusicTableViewCell<br>        let item = items[indexPath.row]<br>        cell.nameLabel.text = item.trackName<br>        cell.photoImageView.image = UIImage(systemName: &quot;music.house&quot;)<br>        URLSession.shared.dataTask(with: item.artworkUrl100) { data, response , error in<br>            if let data = data {<br>                DispatchQueue.main.async {<br>                    cell.photoImageView.image = UIImage(data: data)<br>                }<br>            }<br>        }.resume()<br>        return cell<br>    }</pre><p>資料傳遞</p><p>1.抓取textField的值後，傳遞到一下頁組合API網址</p><pre>//傳資料到下一頁-1<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func goList(_ sender: Any) {<br>        //注意segue的ID命名<br>        performSegue(withIdentifier: &quot;GoResult&quot;, sender: nil)<br>    }<br>    <br>    //傳資料到下一頁-2<br>    <a href="http://twitter.com/IBSegueAction">@IBSegueAction</a> func goResult(_ coder: NSCoder) -&gt; MusicTableViewController? {<br>        let controller = MusicTableViewController(coder: coder)<br>        //注意!!下一頁需宣告這個變數<br>        controller?.singer = textField.text!<br>        return controller<br>    }</pre><p>cell UI</p><ol><li>建立TableViewCell</li><li>拉Label到TableViewCell內</li><li>就能編輯UILabel的資訊了</li></ol><pre>class MusicTableViewCell: UITableViewCell {</pre><pre><a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var nameLabel: UILabel!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var photoImageView: UIImageView!<br>    <br>    <br>    override func awakeFromNib() {<br>        super.awakeFromNib()<br>        // Initialization code<br>    }</pre><pre>override func setSelected(_ selected: Bool, animated: Bool) {<br>        super.setSelected(selected, animated: animated)</pre><pre>// Configure the view for the selected state<br>    }</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*GtMC-rDISu2X9_WQ0PKLHg.png" /><figcaption>點選每一個歌，都能到下一頁試聽音樂</figcaption></figure><p>傳遞資料動作</p><ol><li>接受頁面需建立init</li><li>第一頁拉完Segue後，執行下一頁的init，把要傳的值給丟過去</li></ol><pre>//第一頁<br>//傳資料到下一頁<br>    <a href="http://twitter.com/IBSegueAction">@IBSegueAction</a> func showDetail(_ coder: NSCoder) -&gt; SongDetailViewController? {<br>        //下一個需建一個init<br>        if let row = tableView.indexPathForSelectedRow?.row {<br>            return SongDetailViewController(coder: coder, item: items[row])<br>        } else {<br>            return nil<br>        }<br>    }</pre><pre>//下一頁<br>    init?(coder: NSCoder, item: StoreItem) {<br>        self.item = item<br>        super.init(coder: coder)<br>    }<br>    <br>    required init?(coder: NSCoder) {<br>        fatalError(&quot;init(coder:) has not been implemented&quot;)<br>    }</pre><p>更新第三頁UI</p><pre>    var item: StoreItem //定義給傳資料來的頁面</pre><pre>nameLabel.text = item.trackName<br>        URLSession.shared.dataTask(with: item.artworkUrl500) { data, response , error in<br>            if let data = data {<br>                DispatchQueue.main.async {<br>                    self.imageView.image = UIImage(data: data)<br>                }<br>            }<br>        }.resume()<br>    }</pre><p>放音樂動作</p><ol><li><strong>import</strong> AVFoundation</li><li><strong>var</strong> player: AVPlayer?</li><li>按按鈕就能放音樂囉</li></ol><pre><a href="http://twitter.com/IBAction">@IBAction</a> func paly(_ sender: Any) {<br>        player = AVPlayer(url: item.previewUrl)<br>        player?.play()<br>    }</pre><p>Demo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*RX0istXr5zIWNJxN14kYUg.gif" /></figure><p>附上我的GitHub</p><p><a href="https://github.com/carlton0115354/apiMusic">GitHub - carlton0115354/apiMusic</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba313478c791" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E4%BD%BF%E7%94%A8apple-music-api-%E8%A3%BD%E4%BD%9C%E9%9F%B3%E6%A8%82%E8%BB%9F%E9%AB%94-ba313478c791">使用apple Music API 製作音樂軟體</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[看歌名猜歌手]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E7%9C%8B%E6%AD%8C%E5%90%8D%E7%8C%9C%E6%AD%8C%E6%89%8B-19f81085c3a0?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/19f81085c3a0</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Sat, 16 Apr 2022 06:39:31 GMT</pubDate>
            <atom:updated>2022-04-16T12:47:44.702Z</atom:updated>
            <content:encoded><![CDATA[<p>這次的作業主要是練習把值傳到下一頁</p><p>畫面為</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*LAKf4inRnpeNpBV04GtWTg.png" /></figure><p>使用到的action</p><p>1.UIbutton</p><p>使用到的outlet</p><ol><li>題目</li><li>第N題</li></ol><p>產出題目</p><p>Model</p><pre>struct Song {<br>    var songname: String?<br>    var options: [String]<br>    var answer: String?<br>    <br>    init(songname: String , options: [String] , answer: String){<br>        self.songname = songname<br>        self.options = options<br>        self.answer = answer<br>    }<br>}</pre><p>controller</p><pre>func createSongs() {<br>        Songs = [<br>            Song(songname: &quot;我難過&quot;, options: [&quot;5566&quot;,&quot;183 Club&quot;,&quot;ENERGY&quot;,&quot;K ONE&quot;], answer: &quot;5566&quot;),<br>            Song(songname: &quot;愛上你算我賤&quot;, options: [&quot;周湯豪&quot;,&quot;周華健&quot;,&quot;周杰倫&quot;,&quot;周興哲&quot;], answer: &quot;周湯豪&quot;),<br>            Song(songname: &quot;閣愛妳一擺&quot;, options: [&quot;茄子蛋&quot;,&quot;告五人&quot;,&quot;火腿蛋&quot;,&quot;五月天&quot;], answer: &quot;茄子蛋&quot;),<br>            Song(songname: &quot;重感情的廢物&quot;, options: [&quot;TRASH&quot;,&quot;飛輪海&quot;,&quot;五堅情&quot;,&quot;五月天&quot;], answer: &quot;TRASH&quot;),<br>            Song(songname: &quot;牽心萬苦&quot;, options: [&quot;謝和弦&quot;,&quot;謝金燕&quot;,&quot;謝霆鋒&quot;,&quot;謝長廷&quot;], answer: &quot;謝和弦&quot;),<br>            Song(songname: &quot;我可以&quot;, options: [&quot;蔡旻佑&quot;,&quot;楊宗緯&quot;,&quot;蕭敬騰&quot;,&quot;林宥嘉&quot;], answer: &quot;蔡旻佑&quot;),<br>            Song(songname: &quot;天后&quot;, options: [&quot;陳勢安&quot;,&quot;畢書盡&quot;,&quot;陳港生&quot;,&quot;陳時中&quot;], answer: &quot;陳勢安&quot;),<br>            Song(songname: &quot;帥到分手&quot;, options: [&quot;周湯豪&quot;,&quot;周華健&quot;,&quot;周杰倫&quot;,&quot;周興哲&quot;], answer: &quot;周湯豪&quot;),<br>            Song(songname: &quot;你我可以&quot;, options: [&quot;熊仔&quot;,&quot;MC Hot Dog&quot;,&quot;蛋堡&quot;,&quot;瘦子&quot;], answer: &quot;熊仔&quot;),<br>            Song(songname: &quot;IDOL RAPPER&quot;, options: [&quot;婁峻碩&quot;,&quot;熊仔&quot;,&quot;高爾宣&quot;,&quot;陳時中&quot;], answer: &quot;婁峻碩&quot;),<br>            Song(songname: &quot;愛你&quot;, options: [&quot;陳芳語&quot;,&quot;嚴爵&quot;,&quot;曾沛慈&quot;,&quot;蔡英文&quot;], answer: &quot;陳芳語&quot;),<br>            Song(songname: &quot;啞巴&quot;, options: [&quot;潘瑋柏&quot;,&quot;潘志遠醫師&quot;,&quot;黃品源&quot;,&quot;王傑&quot;], answer: &quot;潘瑋柏&quot;),<br>            Song(songname: &quot;小情歌&quot;, options: [&quot;蘇打綠&quot;,&quot;無糖綠&quot;,&quot;五月天&quot;,&quot;蘇打水&quot;], answer: &quot;蘇打綠&quot;),<br>            Song(songname: &quot;你不知道的事&quot;, options: [&quot;王力宏&quot;,&quot;羅志祥&quot;,&quot;九把刀&quot;,&quot;吳亦凡&quot;], answer: &quot;王力宏&quot;),<br>            Song(songname: &quot;紳士&quot;, options: [&quot;薛之謙&quot;,&quot;李榮浩&quot;,&quot;張衛健&quot;,&quot;張一健&quot;], answer: &quot;薛之謙&quot;),<br>            Song(songname: &quot;戒菸&quot;, options: [&quot;李榮浩&quot;,&quot;薛之謙&quot;,&quot;張衛健&quot;,&quot;張一健&quot;], answer: &quot;李榮浩&quot;),<br>            Song(songname: &quot;我在呢&quot;, options: [&quot;Tank&quot;,&quot;Zack&quot;,&quot;Cook&quot;,&quot;Jack&quot;], answer: &quot;Tank&quot;),<br>            Song(songname: &quot;兜圈&quot;, options: [&quot;林宥嘉&quot;,&quot;蔡旻佑&quot;,&quot;楊宗緯&quot;,&quot;蕭敬騰&quot;], answer: &quot;林宥嘉&quot;),<br>            Song(songname: &quot;倒數&quot;, options: [&quot;鄧紫棋&quot;,&quot;鄧麗君&quot;,&quot;鄧小平&quot;,&quot;鄧秋千&quot;], answer: &quot;鄧紫棋&quot;),<br>            Song(songname: &quot;默念你&quot;, options: [&quot;宋念宇&quot;,&quot;周杰倫&quot;,&quot;王力宏&quot;,&quot;羅志祥&quot;], answer: &quot;宋念宇&quot;),<br>            Song(songname: &quot;告白氣球&quot;, options: [&quot;周杰倫&quot;,&quot;林俊傑&quot;,&quot;周興哲&quot;,&quot;林宥嘉&quot;], answer: &quot;周杰倫&quot;),<br>            Song(songname: &quot;馬子狗&quot;, options: [&quot;八三夭&quot;,&quot;五月天&quot;,&quot;茄子蛋&quot;,&quot;告五人&quot;], answer: &quot;八三夭&quot;),<br>            Song(songname: &quot;Still Life&quot;, options: [&quot;BIGBANG&quot;,&quot;BANGBANG&quot;,&quot;BTS&quot;,&quot;SHINEE&quot;], answer: &quot;BIGBANG&quot;),<br>            Song(songname: &quot;想知道你在想什麼&quot;, options: [&quot;周興哲&quot;,&quot;周立民&quot;,&quot;言承旭&quot;,&quot;蛋堡&quot;], answer: &quot;周興哲&quot;),<br>            Song(songname: &quot;好不容易&quot;, options: [&quot;告五人&quot;,&quot;BIGBANG&quot;,&quot;F4&quot;,&quot;瘦子&quot;], answer: &quot;告五人&quot;),<br>        ]<br>    }</pre><p>這樣題目就產出來囉</p><p>再來是答案的按鈕<br>判斷點選的與正確答案是否相同<br>然後第10題時會使用到alert function</p><pre><a href="http://twitter.com/IBAction">@IBAction</a> func choose(_ sender: Any) {<br>        let Button = sender as! UIButton<br>        //選擇的答案<br>        let chooseAnswer : String = Songs[Number].options[Button.tag]<br>        //正確答案<br>        let correctAnser : String = Songs[Number].answer!<br>        //比較<br>        if chooseAnswer == correctAnser {<br>            print(&quot;答對了&quot;)<br>            correctNumber = correctNumber + 1<br>        } else {<br>            print(&quot;答錯了&quot;)<br>            errorNumber = errorNumber + 1<br>        }<br>        <br>        //判斷10題後<br>        if Number &lt; 9 {<br>            Number = Number + 1<br>            setUI(Number: Number)<br>        } else {<br>            alert(title: &quot;通知!!&quot;, message: &quot;已經10題囉~&quot;, button: &quot;OK&quot;)<br>        }<br>    }</pre><p>alert function<br>如果點選ok時會到下一頁</p><pre>func alert(title: String , message: String, button: String){<br>        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)<br>        //按鈕<br>        let okAction = UIAlertAction(title: button, style: .default) { (okAction) in<br>                    <br>            self.performSegue(withIdentifier: &quot;resultViewController&quot;, sender: nil)<br>                    <br>                }<br>        //將按鈕加入本體<br>        alert.addAction(okAction)<br>        //persent出來<br>        present(alert,animated: true,completion: nil)<br>    }</pre><p>還有畫面的segue 要設定</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*ngfOsUQdc8Y2chVg1cvslQ.png" /></figure><p>另一個重要的是<br>到下一頁時會把值丟到下一頁的2個欄位</p><pre><a href="http://twitter.com/IBSegueAction">@IBSegueAction</a> func goResult(_ coder: NSCoder) -&gt; resultViewController? {<br>        let controller = resultViewController(coder: coder)<br>        controller?.correctNumber = correctNumber<br>        controller?.errorNumber = errorNumber<br>        return controller<br>    }</pre><p>result頁面 <br>從前頁傳來的值前，要先定義，否則會閃退</p><pre>var correctNumber : Int = 0 //答對題數<br>var errorNumber : Int = 0 //答錯題數</pre><p>附上demo gif</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*3PjEXCnRT3jChhF_NBJGGQ.gif" /></figure><p><a href="https://github.com/carlton0115354/GuessTheSong">GitHub - carlton0115354/GuessTheSong</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19f81085c3a0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E7%9C%8B%E6%AD%8C%E5%90%8D%E7%8C%9C%E6%AD%8C%E6%89%8B-19f81085c3a0">看歌名猜歌手</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[來划拳吧！！]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E4%BE%86%E5%88%92%E6%8B%B3%E5%90%A7-a6d5b15bdc17?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6d5b15bdc17</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Sun, 10 Apr 2022 15:32:51 GMT</pubDate>
            <atom:updated>2022-04-12T06:04:13.776Z</atom:updated>
            <content:encoded><![CDATA[<p>這次來做一個把資料傳遞到下一頁的app<br>於是做了這個划拳遊戲</p><p>因為划拳前要先猜拳，所以把勝負給傳遞到下一頁了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*G801pFkD6F_vQ3-6qSFDXg.png" /></figure><p>簡單的2個畫面</p><p>第一個畫面就是單純的猜拳</p><p>第二個畫面就是划拳頁面</p><p>action</p><ol><li>猜拳(剪刀石頭布)</li><li>0.5按鈕</li><li>UISegmentedControl</li></ol><p>outlet</p><ol><li>誰先開始</li><li>輪到誰</li><li>喊的數字</li><li>電腦出的拳</li><li>猜拳<br>平手不會進入到下一頁</li></ol><pre><a href="http://twitter.com/IBAction">@IBAction</a> func HandGame(_ sender: UIButton) {<br>        let ImageRondon = Int.random(in: 0...2)<br>        computerButton.text = computerImage[ImageRondon]<br>        //sender.tag 0 = 剪刀<br>        //sender.tag 1 = 石頭<br>        //sender.tag 2 = 布<br>        if ImageRondon == sender.tag {<br>            print(&quot;平手&quot;)<br>        } else {<br>            if ImageRondon == 0 {<br>                if sender.tag == 1 {<br>                    print(&quot;玩家贏了&quot;)<br>                    whofirst = &quot;玩家先&quot;<br>                } else {<br>                    print(&quot;電腦贏了&quot;)<br>                    whofirst = &quot;電腦先&quot;<br>                }<br>            } else if ImageRondon == 1 {<br>                if sender.tag == 0 {<br>                    print(&quot;電腦贏了&quot;)<br>                    whofirst = &quot;電腦先&quot;<br>                } else {<br>                    print(&quot;玩家贏了&quot;)<br>                    whofirst = &quot;玩家先&quot;<br>                }<br>            } else {<br>                if sender.tag == 0 {<br>                    print(&quot;玩家贏了&quot;)<br>                    whofirst = &quot;玩家先&quot;<br>                } else {<br>                    print(&quot;電腦贏了&quot;)<br>                    whofirst = &quot;電腦先&quot;<br>                }<br>            }<br>            performSegue(withIdentifier: &quot;enterGaming&quot;, sender: &quot;贏了&quot;)<br>        }<br>    }<br>    <br>    <a href="http://twitter.com/IBSegueAction">@IBSegueAction</a> func showGameVIew(_ coder: NSCoder) -&gt; FiveTenFifteenViewController? {<br>        let controller = FiveTenFifteenViewController(coder: coder)<br>        controller?.whoWin = whofirst<br>        return controller<br>    }</pre><p>2. 0.5按鈕<br> 左邊按其中一個，另一個會隱藏掉</p><pre><a href="http://twitter.com/IBAction">@IBAction</a> func playGame(_ sender: UIButton) {<br>        if sender.tag == 1 {<br>            leftFiveButton.setTitle(&quot;&quot;, for: .normal)<br>            leftFiveButton.isEnabled = false<br>            leftNumber = 0<br>        } else if sender.tag == 2 {<br>            leftZeroButton.setTitle(&quot;&quot;, for: .normal)<br>            leftZeroButton.isEnabled = false<br>            leftNumber = 5<br>        } else if sender.tag == 3 {<br>            rightFiveButton.setTitle(&quot;&quot;, for: .normal)<br>            rightFiveButton.isEnabled = false<br>            RightNumber = 0<br>        } else {<br>            rightZeroButton.setTitle(&quot;&quot;, for: .normal)<br>            rightZeroButton.isEnabled = false<br>            RightNumber = 5<br>        }<br>            if leftNumber != nil &amp;&amp; RightNumber != nil {<br>                /* 出拳部分 */<br>                if whoFirst.text == &quot;換玩家&quot; {<br>                    /*電腦只出拳*/<br>                    comPunch()<br>                    print(&quot;開始&quot;)<br>                    print(userStepper.selectedSegmentIndex)<br>                    minesLabel.text = &quot;\(total[userStepper.selectedSegmentIndex])&quot;<br>                    getTotal()<br>                } else {<br>                    /*電腦只出拳 ＋ 喊數字*/<br>                    comPunch()<br>                    comKeyRandom = Int.random(in: 0...total.count-1)<br>                    minesLabel.text = &quot;\(total[comKeyRandom])&quot;<br>                    getTotal()<br>                }<br>                /* 比對勝負 */<br>                if minesLabel.text! == &quot;\(allTotal!)&quot; {<br>                    if whoFirst.text == &quot;換玩家&quot; {<br>                        alert(title: &quot;恭喜&quot;, message: &quot;贏囉！！&quot;, button: &quot;確認&quot;)<br>                    } else {<br>                        alert(title: &quot;太可惜了&quot;, message: &quot;需要再努力&quot;, button: &quot;確認&quot;)<br>                    }<br>                } else {<br>                    if whoFirst.text == &quot;換玩家&quot; {<br>                        whoFirst.text = &quot;換電腦&quot;<br>                    } else {<br>                        whoFirst.text = &quot;換玩家&quot;<br>                    }<br>                    alert(title: &quot;再次努力&quot;, message: &quot;GOGO&quot;, button: &quot;確認&quot;)<br>                }<br>                resetting()<br>            }<br>    }</pre><p>附上Demo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*zXuN0Ci7WU8UbkorGFg0WQ.gif" /><figcaption>玩得有點久…一直平手</figcaption></figure><p>詳情請到我的GitHub看</p><p><a href="https://github.com/carlton0115354/FiveTenFifteen">GitHub - carlton0115354/FiveTenFifteen</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6d5b15bdc17" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E4%BE%86%E5%88%92%E6%8B%B3%E5%90%A7-a6d5b15bdc17">來划拳吧！！</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[撲克牌遊戲-射龍門]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E6%92%B2%E5%85%8B%E7%89%8C%E9%81%8A%E6%88%B2-%E5%B0%84%E9%BE%8D%E9%96%80-24114575f800?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/24114575f800</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Tue, 05 Apr 2022 07:54:44 GMT</pubDate>
            <atom:updated>2022-04-05T13:48:58.714Z</atom:updated>
            <content:encoded><![CDATA[<p>原本想說連假第一天就要把這個app完成，結果…</p><p>最後一天才完成…</p><p>射龍門是從小到大過年會玩的遊戲</p><p>規則是:</p><ol><li>下籌碼</li><li>開龍門</li><li>開牌</li><li>若牌在龍門範圍內，莊家則會給你籌碼的錢；在龍門外，莊家則會把錢收回去</li><li>若撞柱，卡牌與龍門數字相符，則要給出Double的籌碼；若卡牌與龍門數字3個都一樣，則要給出3倍的籌碼</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWs0jEy-EyKC0seHnbntlg.png" /></figure><p>用到的action</p><ol><li>UIStepper 控制下注金額</li><li>UIButton 控制龍門圖片及射龍門</li></ol><p>— — — —</p><ol><li><strong><em>撲克牌</em></strong></li></ol><p>利用 func 來方便可以重複使用</p><pre>func createPoker() {<br>        Pokers = [ Poker(suit: &quot;♠️&quot; , number: &quot;A&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;2&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;3&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;4&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;5&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;6&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;7&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;8&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;9&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;10&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;J&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;Q&quot;),<br>                   Poker(suit: &quot;♠️&quot; , number: &quot;K&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;A&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;2&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;3&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;4&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;5&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;6&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;7&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;8&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;9&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;10&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;J&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;Q&quot;),<br>                   Poker(suit: &quot;❤️&quot; , number: &quot;K&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;A&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;2&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;3&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;4&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;5&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;6&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;7&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;8&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;9&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;10&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;J&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;Q&quot;),<br>                   Poker(suit: &quot;♦️&quot; , number: &quot;K&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;A&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;2&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;3&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;4&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;5&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;6&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;7&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;8&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;9&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;10&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;J&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;Q&quot;),<br>                   Poker(suit: &quot;♣️&quot; , number: &quot;K&quot;),<br>        ]<br>    }</pre><p><strong><em>2.UIStepper</em></strong></p><p>當龍門還沒開時，還可以進行下注動作</p><pre>//下注按鈕<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func ChangeStepper(_ sender: UIStepper) {<br>        if MaxPokerImage.image == nil &amp;&amp; MinPokerImage.image == nil {<br>            sender.maximumValue = Double(MaxMoneyLabel.text!) ?? 0<br>            PayMoneyLabel.text =  &quot;\(Int(sender.value))&quot;<br>            if Int(PayMoneyLabel.text!)! &gt; Int(MaxMoneyLabel.text!)! {<br>                alert(title: &quot;注意&quot;, message: &quot;籌碼不夠&quot;, button: &quot;確認&quot;)<br>            }<br>        }<br>    }</pre><p>3.UIButton</p><p>3–1 開龍門</p><p>使用亂數隨機翻牌，前提是還有錢錢可以玩時</p><pre><a href="http://twitter.com/IBAction">@IBAction</a> func OpenDoor(_ sender: UIButton) {<br>        if MaxPokerImage.image == nil || MinPokerImage.image == nil {<br>            Stepper.isEnabled = false<br>            if Int(MaxMoneyLabel.text!)! &gt; 0 {<br>                if sender.tag == 0 { //尚未開門時，開一扇門<br>                    sender.tag = 1<br>                    let minRadomNumber = Int.random(in: 0...Pokers.count-1)<br>                    opeDragonDoor(num: minRadomNumber, type: &quot;min&quot;) //翻盤<br>                    Pokers.remove(at: minRadomNumber) //刪除該筆資料<br>                    changePokerTotal() //變更剩餘牌數<br>                } else if sender.tag == 1 { //開一扇門時，開第二扇<br>                    sender.tag = 2<br>                    let maxRadomNumber = Int.random(in: 0...Pokers.count-1)<br>                    opeDragonDoor(num: maxRadomNumber, type: &quot;max&quot;) //翻牌<br>                    Pokers.remove(at: maxRadomNumber) //刪除該筆資料<br>                    changePokerTotal()//變更剩餘牌數<br>                    //openDrgonButton.setTitle(&quot;開龍門&quot;, for:.normal)<br>                    openDrgonButton.isEnabled = false<br>                }<br>            } else {<br>                alert(title: &quot;注意!!&quot;, message: &quot;沒錢怎麼玩...!!&quot;, button: &quot;確認&quot;)<br>            }<br>        } else {<br>            sender.tag = 0<br>            openDrgonButton.setTitle(&quot;開龍門&quot;, for:.normal)<br>            Stepper.isEnabled = true<br>            cleanImage()<br>        }<br>    }</pre><p>3–2 射龍門</p><p>簡單的判斷大小，去使用加錢扣錢func</p><pre>//射龍門<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func PlayGame(_ sender: UIButton) {<br>        if Int(MaxMoneyLabel.text!)! &gt; 0 {<br>            if openPokerImage.image == nil {<br>                //如果還沒開龍門時<br>                if MinPokerImage.image != nil &amp;&amp; MaxPokerImage.image != nil {<br>                    let RadomNumber = Int.random(in: 0...Pokers.count-1)<br>                    opeDragonDoor(num: RadomNumber, type: &quot;play&quot;) //翻牌<br>                    Pokers.remove(at: RadomNumber) //刪除該筆資料<br>                    changePokerTotal() //變更剩餘牌數<br>                    <br>                    //判斷輸贏 //回傳Int 好比大小<br>                    let max : Int = CheckJQKNumber(Poker: tmpMaxPoker)<br>                    let min : Int = CheckJQKNumber(Poker: tmpMinPoker)<br>                    let open : Int = CheckJQKNumber(Poker: tmpOpenPoker)</pre><pre>//處理牌<br>                    if open == max || open == min {<br>                        alert(title: &quot;一般撞柱!!&quot;, message: &quot;賠下注金額2倍&quot;, button: &quot;幫QQ&quot;)<br>                        changeMaxMoneyLabel(transport: &quot;-&quot;, multiple: 2)<br>                    } else { //沒撞柱的話才判斷<br>                    //先判斷左邊大還是右邊大<br>                        if max &gt; min {<br> if open &lt; max &amp;&amp; open &gt; min {<br>                                alert(title: &quot;恭喜!!&quot;, message: &quot;PASS&quot;, button: &quot;確認&quot;)<br>                                changeMaxMoneyLabel(transport: &quot;+&quot;, multiple: 1)<br>                            } else {<br>                                alert(title: &quot;真可惜&quot;, message: &quot;賠下注金額&quot;, button: &quot;確認&quot;)<br>                                changeMaxMoneyLabel(transport: &quot;-&quot;, multiple: 1)<br>                            }<br>                        } else if max &lt; min {<br>                            if open &gt; max &amp;&amp; open &lt; min {<br>                                alert(title: &quot;恭喜!!&quot;, message: &quot;PASS&quot;, button: &quot;確認&quot;)<br>                                changeMaxMoneyLabel(transport: &quot;+&quot;, multiple: 1)<br>                            } else {<br>                                alert(title: &quot;真可惜&quot;, message: &quot;賠下注金額&quot;, button: &quot;確認&quot;)<br>                                changeMaxMoneyLabel(transport: &quot;-&quot;, multiple: 1)<br>                            }<br>                        } else if max == min {<br>                            if open == max &amp;&amp; open == min {<br>                                alert(title: &quot;對子撞柱!!&quot;, message: &quot;賠下注金額3倍&quot;, button: &quot;幫QQ&quot;)<br>                                changeMaxMoneyLabel(transport: &quot;-&quot;, multiple: 3)<br>                            } else {<br>                                alert(title: &quot;真可惜&quot;, message: &quot;賠下注金額&quot;, button: &quot;確認&quot;)<br>                                changeMaxMoneyLabel(transport: &quot;-&quot;, multiple: 1)<br>                            }<br>                        }<br>                    }<br>                    openDrgonButton.setTitle(&quot;清空&quot;, for:.normal)<br>                    openDrgonButton.isEnabled = true<br>                } else {<br>                    alert(title: &quot;注意!!&quot;, message: &quot;先開門喔~&quot;, button: &quot;確認&quot;)<br>                }<br>            }<br>        } else {<br>            alert(title: &quot;注意!!&quot;, message: &quot;沒錢怎麼玩...!!&quot;, button: &quot;確認&quot;)<br>        }</pre><p>3–3 ALLIN</p><p>若還沒開牌時，可以allin</p><pre>//梭哈<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func allIn(_ sender: UIButton) {<br>        if MinPokerImage.image == nil &amp;&amp; MaxPokerImage.image == nil {<br>            PayMoneyLabel.text = MaxMoneyLabel.text<br>        }<br>        <br>    }</pre><p>3–4 重新開始</p><p>把基本資訊設回預設值</p><pre><a href="http://twitter.com/IBAction">@IBAction</a> func restart(_ sender: UIButton) {<br>            MaxMoneyLabel.text = &quot;1000&quot;<br>            PayMoneyLabel.text = &quot;100&quot;<br>            createPoker()<br>            cleanImage()<br>            changePokerTotal()<br>            openDrgonButton.tag = 0<br>            openDrgonButton.setTitle(&quot;開龍門&quot;, for:.normal)<br>            openDrgonButton.isEnabled = true<br>            Stepper.isEnabled = true<br>        }</pre><p>附上Demo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*hyZI7HPFzKA7zfjmmFUNhg.gif" /></figure><p>附上我的GitHub</p><p><a href="https://github.com/carlton0115354/PokerGame">GitHub - carlton0115354/PokerGame</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24114575f800" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E6%92%B2%E5%85%8B%E7%89%8C%E9%81%8A%E6%88%B2-%E5%B0%84%E9%BE%8D%E9%96%80-24114575f800">撲克牌遊戲-射龍門</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MyMusic Player]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/mymusic-player-5d2b75ba1f49?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d2b75ba1f49</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 14:13:25 GMT</pubDate>
            <atom:updated>2022-03-31T07:17:41.128Z</atom:updated>
            <content:encoded><![CDATA[<p>使用UIKit來做出放音樂APP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*Yy0A1Z3z_iVfgd0kX3_u2w.png" /><figcaption>IU推推!!</figcaption></figure><p>使用到功能</p><ol><li>UIslider 控制播放時間及顯示時間</li><li>控制音量</li><li>使用AVFoundation 及 MediaPlayer 套件</li></ol><p>使用到action</p><ol><li>上下一首</li><li>Play &amp; Stop</li><li>循環&amp;單首循環</li><li>開關隨機播放</li></ol><p>5. UIslier 控制時間</p><p>重點:放音樂</p><pre>//放音樂function 及 換照片&amp;label<br>    func playSong(number: Int){<br>        //play動作<br>        let fileUrl = Bundle.main.url(/service/forresource: PlayLists[number].name!, withExtension: &quot;mp3&quot;)!<br>        let playerItem = AVPlayerItem(url: fileUrl)<br>        player.replaceCurrentItem(with: playerItem)<br>        player.play()<br>        <br>        //設定時間<br>        //修改顯示<br>        let duration = CMTimeGetSeconds(playerItem.asset.duration)<br>        maxTIme.text = formatConversion(time: duration)<br>        <br>        //  重置slider和播放軌道<br>        songSlider.setValue(Float(0), animated: true)<br>        let TargetTime:CMTime = CMTimeMake(value: Int64(0), timescale: 1)<br>        player.seek(to: TargetTime)<br>        <br>        //設定slider最大最小值<br>        let Duration :CMTime = playerItem.asset.duration<br>        let Seconds:Float64 = CMTimeGetSeconds(Duration)<br>            songSlider.minimumValue = 0<br>            songSlider.maximumValue = Float(Seconds)<br>        <br>        changeImage(number: number)//換第N照片<br>        changeLabel(number: number)//第N首歌資訊<br>    }</pre><p><strong><em>上下一首</em></strong></p><p>有判斷是否單首循環與隨機播放</p><pre>//上一首&amp;下一首<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func nextSong(_ sender: UIButton) {<br>        print(randomButton.tag)<br>        if oneSong.tag ==  0 { //單首循環<br>            if randomButton.tag == 0 {<br>                if sender.tag == 0 { //判斷是下一首 還是 上一首<br>                    if index == PlayLists.count - 1 { //若是最後一首，會跳到第一首<br>                        index = 0<br>                    } else {<br>                        index = index + 1<br>                    }<br>                } else {<br>                    if index == 0 { //若是第一首，會跳到最後一首<br>                        index = PlayLists.count - 1<br>                    } else {<br>                        index = index - 1<br>                    }<br>                }<br>            } else {<br>                index = Int.random(in: 0...PlayLists.count - 1)<br>            }<br>        }<br>        playSong(number: index)//放音樂<br>        CurrentTime()  //讓slider跟著動<br>    }</pre><p>2. Play &amp; Stop</p><pre>//播放＆暫停<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func playAndStop(_ sender: UIButton) {<br>        print(player.rate)<br>        if player.rate == 0 { //如果是暫停時，觸控代表放音樂<br>            player.play()<br>            stopSong.setImage(stopImage, for: .normal)<br>        } else {<br>            player.pause()<br>            stopSong.setImage(playImage, for: .normal)<br>        }<br>    }</pre><p>3. 循環&amp;單首循環</p><pre>//單曲循環按鈕<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func openCloseOneSony(_ sender: UIButton) {<br>        if oneSong.tag == 0 { //開啟單首循環<br>            print(&quot;開啟單首循環&quot;)<br>            oneSong.setImage(loopModeOnIcon, for: .normal)<br>            oneSong.tag = 1<br>        } else {<br>            print(&quot;關閉單首循環&quot;)<br>            oneSong.setImage(loopModeOffIcon, for: .normal)<br>            oneSong.tag = 0<br>        }<br>        print(oneSong.tag)<br>    }</pre><p>4. 開關隨機播放</p><pre>//隨機&amp;按照順序播放按鈕<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func randomAndOrder(_ sender: UIButton) {<br>        if sender.tag == 1 { //開啟隨機<br>            randomButton.setImage(orderSonyImage, for: .normal)<br>            print(&quot;關閉隨機&quot;)<br>            randomButton.tag = 0<br>        } else { //關閉隨機<br>            randomButton.tag = 1<br>            print(&quot;開啟隨機&quot;)<br>            randomButton.setImage(randomSonyImage, for: .normal)<br>        }<br>        print(randomButton.tag)<br>    }</pre><p>5. Slider 控制時間</p><pre>//拖曳slider 會控制音樂幾分幾秒<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func SongSliderAction(_ sender: UISlider) {<br>        let Seconds : Int64 = Int64(songSlider.value)<br>        //  計算秒數<br>        let TargetTime :CMTime = CMTimeMake(value: Seconds, timescale: 1)<br>        //  設定player播放進度<br>        player.seek(to: TargetTime)<br>    }</pre><p>附上操作影片</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*HHWv5sNUR6_Ds_slCmSO9g.gif" /></figure><p>附上Github</p><p><a href="https://github.com/carlton0115354/myMusic">https://github.com/carlton0115354/myMusic</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d2b75ba1f49" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/mymusic-player-5d2b75ba1f49">MyMusic Player</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[終極密碼…!]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E7%B5%82%E6%A5%B5%E5%AF%86%E7%A2%BC-125f6c2edfcd?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/125f6c2edfcd</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 14:18:33 GMT</pubDate>
            <atom:updated>2022-03-27T14:38:34.110Z</atom:updated>
            <content:encoded><![CDATA[<p>目的: 學習產生隨機數字，數字和字串之間的轉換。</p><p>到了一定年紀後，還是會玩這個遊戲嗎???</p><p>輸的喝一杯?還是直接一盤Shot了??</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*N2x4bYPWRjyCqZ-Xm1mX0g.png" /><figcaption>很陽春的介面…承認我沒有什麼審美觀..Orz</figcaption></figure><p>用到的功能：</p><ol><li>UIButton…沒了!!…滿滿的button…</li></ol><p>能觸發的IBAction有</p><ol><li>點擊數字後，會顯示輸入的文字</li><li>重新輸入文字</li><li>重新開始遊戲</li><li>判斷是否踩到炸彈</li></ol><p><strong><em>點擊數字後，會顯示輸入的文字</em></strong></p><p>檢查字數是否大於2，否則會有錯誤訊息!!</p><pre>//數字鍵<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func numberButton(_ sender: UIButton) {<br>        //print(sender.currentTitle!)<br>        if totalLabel.text!.count &gt; 1 {<br>            alert(title: &quot;注意!&quot;, message: &quot;最多2個字!&quot;, button: &quot;收到&quot;)<br>        } else {<br>            totalLabel.text! += sender.currentTitle!<br>        }<br>    }</pre><p><strong><em>重新輸入文字</em></strong></p><pre>//重新輸入<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func clearLabel(_ sender: UIButton) {<br>        clearTotalLabel() <br>    }</pre><pre>    //清空輸入的文字<br>    func clearTotalLabel() {<br>        totalLabel.text! = &quot;&quot;<br>    }</pre><p><strong><em>重新開始遊戲</em></strong></p><pre>//重新一場遊戲<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func reStart(_ sender: UIButton) {<br>        clearLabel()<br>        getNewKey()<br>        clearTotalLabel()<br>        alert(title: &quot;OK!&quot;, message: &quot;已幫你從設密碼囉!!&quot;, button: &quot;GoGO&quot;)<br>    }</pre><pre>    func clearLabel() {<br>        minLabel.text = &quot;0&quot;<br>        maxLabel.text = &quot;100&quot;<br>        touchNumberLabel.text = &quot;0&quot;<br>    }<br>    <br>    //重新開始，產生新的炸彈<br>    func getNewKey() {<br>        key = Int.random(in: 1...99)<br>    }</pre><p><strong><em>判斷是否踩到炸彈</em></strong></p><p>判斷輸入的數字大於&amp;小於&amp;等於炸彈</p><p>否則會去更新對應的到欄位</p><pre>//送出按鈕<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func submit(_ sender: UIButton) {<br>        let tmpInput = Int(totalLabel.text!)! //把輸入值丟到tmpInput內<br>        //先判斷輸入的是否 小於最小 &amp;&amp; 大於最大<br>        if tmpInput &gt; Int(minLabel.text!)! &amp;&amp; tmpInput &lt; Int(maxLabel.text!)! {<br>            //輸入值與炸彈比較<br>            if tmpInput &lt; key {<br>                minLabel.text = &quot;\(tmpInput)&quot; //若比炸彈小 修改最小值<br>            } else if tmpInput &gt; key {<br>                maxLabel.text = &quot;\(tmpInput)&quot; //若比炸彈大 修改最大值<br>            } else {<br>                //猜對後&amp;清空字串&amp;跳訊息&amp;重新開始<br>                alert(title: &quot;完成!&quot;, message: &quot;恭喜猜對囉~~&quot;, button: &quot;結束&quot;)<br>                clearLabel()<br>                getNewKey()<br>                <br>            }<br>            touchNumberLabel.text = &quot;\(Int(touchNumberLabel.text!)! + 1)&quot; //使用次數累加<br>        } else {<br>            alert(title: &quot;賣鬧!!&quot;, message: &quot;看清楚再猜，這次放過你，不算你一次的機會!!&quot;, button: &quot;對不起Orz&quot;)<br>        }<br>        print(key)<br>        totalLabel.text = &quot;&quot; //清空輸入匡欄位<br>    }</pre><p>Demo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*hyp-xU8XWaYx1lTKkAxvJg.gif" /></figure><p>附上我的GitHub</p><p><a href="https://github.com/carlton0115354/ultimate-password">GitHub - carlton0115354/ultimate-password</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=125f6c2edfcd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E7%B5%82%E6%A5%B5%E5%AF%86%E7%A2%BC-125f6c2edfcd">終極密碼…!</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DatePicker練習 計算生命靈數]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/datepicker%E7%B7%B4%E7%BF%92-%E8%A8%88%E7%AE%97%E7%94%9F%E5%91%BD%E9%9D%88%E6%95%B8-febc3fe72b19?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/febc3fe72b19</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 11:45:41 GMT</pubDate>
            <atom:updated>2022-03-27T14:35:20.453Z</atom:updated>
            <content:encoded><![CDATA[<p>兩光師來算命囉</p><p>來幫自己算算命吧!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*wWqm0UYewsUQIbEHlUea4w.png" /><figcaption>SeaFood不好意思，借我練習一下&gt;&lt;</figcaption></figure><p>用到的功能：</p><ol><li>UIDatePicker</li><li>UIButton</li></ol><p>能觸發的IBAction有</p><ol><li>嗯…就只有UIButton，按下Button後，會抓取選取的日期，</li></ol><p>再來是計算出年紀.星座.生肖及生命密碼</p><p>而我的習慣是把資訊都用陣列包起來，包含星座.生肖及狀態</p><pre>//預設陣列<br>    var newConstellation = [&quot;水瓶座&quot;,&quot;雙魚座&quot;,&quot;白羊座&quot;,&quot;金牛座&quot;,&quot;雙子座&quot;,&quot;巨蟹座&quot;,&quot;獅子座&quot;,&quot;處女座&quot;,&quot;天秤座&quot;,&quot;天蠍座&quot;,&quot;射手座&quot;,&quot;摩羯座&quot;]<br>    var newAnimal = [&quot;鼠&quot;,&quot;牛&quot;,&quot;虎&quot;,&quot;兔&quot;,&quot;龍&quot;,&quot;蛇&quot;,&quot;馬&quot;,&quot;羊&quot;,&quot;猴&quot;,&quot;雞&quot;,&quot;狗&quot;,&quot;豬&quot;]<br>    var passwdStatusMessage = [&quot;&quot;,&quot;財運&quot;,&quot;事業&quot;,&quot;愛情&quot;,&quot;親情&quot;,&quot;友情&quot;,&quot;運氣&quot;,&quot;健康&quot;,&quot;眼睛&quot;,&quot;學業&quot;,&quot;天氣&quot;]</pre><p>處理星座：基本上判斷日期後，抓取陣列內的第N筆</p><pre>//處理星座<br>        let constellationNumber: Int<br>        if month == 1 &amp;&amp; day &gt;= 19 || month == 2 &amp;&amp; day &lt;= 19 {<br>            //水瓶座<br>            constellationNumber = 0<br>        }else if month == 2 &amp;&amp; day &gt;= 20 || month == 3 &amp;&amp; day &lt;= 20 {<br>            //雙魚座<br>            constellationNumber = 1<br>        }else if month == 3 &amp;&amp; day &gt;= 21 || month == 4 &amp;&amp; day &lt;= 20 {<br>            //白羊座<br>            constellationNumber = 2<br>        }else if month == 4 &amp;&amp; day &gt;= 21 || month == 5 &amp;&amp; day &lt;= 20 {<br>            //金牛座<br>            constellationNumber = 3<br>        }else if month == 5 &amp;&amp; day &gt;= 21 || month == 6 &amp;&amp; day &lt;= 20 {<br>            //雙子座<br>            constellationNumber = 4<br>        }else if month == 6 &amp;&amp; day &gt;= 21 || month == 7 &amp;&amp; day &lt;= 22 {<br>            //巨蟹座<br>            constellationNumber = 5<br>        }else if month == 7 &amp;&amp; day &gt;= 23 || month == 8 &amp;&amp; day &lt;= 22 {<br>            //獅子座<br>            constellationNumber = 6<br>        }else if month == 8 &amp;&amp; day &gt;= 23 || month == 9 &amp;&amp; day &lt;= 22 {<br>            //處女座<br>            constellationNumber = 7<br>        }else if month == 9 &amp;&amp; day &gt;= 23 || month == 10 &amp;&amp; day &lt;= 22 {<br>            //天秤座<br>            constellationNumber = 8<br>        }else if month == 10 &amp;&amp; day &gt;= 23 || month == 11 &amp;&amp; day &lt;= 22 {<br>            //天蠍座<br>            constellationNumber = 9<br>        }else if month == 11 &amp;&amp; day &gt;= 23 || month == 12 &amp;&amp; day &lt;= 22 {<br>            //射手座<br>            constellationNumber = 10<br>        }else{<br>            //摩羯座<br>            constellationNumber = 11<br>        }</pre><p>處理年紀：抓取選擇的欄位及現在時間，去做加減動作</p><pre>let today = Date()<br>        let nowComponents = Calendar.current.dateComponents(in: TimeZone.current, from: today)<br>        let nowYear = nowComponents.year!<br>        var age = nowYear - year //年紀<br>        //年紀小於0，顯示0<br>        if age &lt; 0 {<br>            age = 0<br>        }</pre><p>處理生肖：(選擇的年份-4 )% 12 的值 就是陣列內的第n筆</p><pre>//處理生肖<br>        let animalNumber = (year - 4) % 12 // (選的年份-4) % 12 取餘數 = 陣列第幾筆<br>        //更換資訊<br>        changeFile(constellationNumber: constellationNumber, animalNumber: animalNumber,age: age)<br>        var passwd : Int  = getPasswd()<br>        passwdLabel.text = &quot;\(passwd)&quot;<br>        passwdStatusLabel.text = passwdStatusMessage[passwd]</pre><p>Demo部分</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*BCTpQvi5VtfSOH9A0gDfeA.gif" /></figure><p>附上我的Github</p><p><a href="https://github.com/carlton0115354/DatePickey">GitHub - carlton0115354/DatePickey</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=febc3fe72b19" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/datepicker%E7%B7%B4%E7%BF%92-%E8%A8%88%E7%AE%97%E7%94%9F%E5%91%BD%E9%9D%88%E6%95%B8-febc3fe72b19">DatePicker練習 計算生命靈數</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用亂數決定今天禮拜幾]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E4%BD%BF%E7%94%A8%E4%BA%82%E6%95%B8%E6%B1%BA%E5%AE%9A%E4%BB%8A%E5%A4%A9%E7%A6%AE%E6%8B%9C%E5%B9%BE-5165ccccba63?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5165ccccba63</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 06:38:44 GMT</pubDate>
            <atom:updated>2022-03-27T14:36:50.941Z</atom:updated>
            <content:encoded><![CDATA[<p>小時候最常說的猴子繞口令</p><p>星期一，猴子…..</p><p>星期二，猴子……</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*mfnhS0E0V1MWTSp3bMIpZg.png" /><figcaption>可愛的猴子</figcaption></figure><p>現在把星期幾亂數化了</p><pre><a href="http://twitter.com/IBAction">@IBAction</a> func Change(_ sender: Any) {<br>        let number = Int.random(in: 0...6)<br>        changeMonkey(number: number)<br>    }</pre><p>使用亂數後，帶入到changeMonkey內</p><pre>func changeMonkey(number: Int){<br>        WeekLabel.text = newWeekLabel[number]<br>        whatLabel.text = newWhatLabel[number]<br>        monkeyImage.image = UIImage(named: newImage[number])<br>    }</pre><p>會把星期給帶入到陣列內</p><pre>var newImage = [&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;<br>                 ,&quot;Saturday&quot;,&quot;Sunday&quot;]<br>    var newWeekLabel = [&quot;星期一，&quot;,<br>                        &quot;星期二，&quot;,<br>                        &quot;星期三，&quot;,<br>                        &quot;星期四，&quot;,<br>                        &quot;星期五，&quot;,<br>                        &quot;星期六，&quot;,<br>                        &quot;星期日，&quot;]<br>    var newWhatLabel = [&quot;猴子穿新衣。&quot;,<br>                        &quot;猴子肚子餓。&quot;,<br>                        &quot;猴子去爬山。&quot;,<br>                        &quot;猴子去考試。&quot;,<br>                        &quot;猴子去跳舞。&quot;,<br>                        &quot;猴子去斗六。&quot;,<br>                        &quot;猴子過生日。&quot;]</pre><p>而我的習慣是會把這些資訊用陣列包起來，才不用用if..else判斷</p><p>雖然功能很簡陋，但是是我第一次使用亂數的功能…</p><p>Demo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*On7dc3l_62h5jryO4VN6GA.gif" /><figcaption>一直按，不會停</figcaption></figure><p>附上Github</p><p><a href="https://github.com/carlton0115354/Monkey">GitHub - carlton0115354/Monkey</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5165ccccba63" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E4%BD%BF%E7%94%A8%E4%BA%82%E6%95%B8%E6%B1%BA%E5%AE%9A%E4%BB%8A%E5%A4%A9%E7%A6%AE%E6%8B%9C%E5%B9%BE-5165ccccba63">使用亂數決定今天禮拜幾</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[來買雙鞋子吧!!]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E4%BE%86%E8%B2%B7%E9%9B%99%E9%9E%8B%E5%AD%90%E5%90%A7-f7adeb889751?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7adeb889751</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Sat, 26 Mar 2022 16:32:14 GMT</pubDate>
            <atom:updated>2022-03-27T04:02:44.417Z</atom:updated>
            <content:encoded><![CDATA[<p>Money 遊戲!!</p><p>那就來買鞋子吧!!!</p><p>人生其中一個夢想就是擁有一整片的鞋牆</p><p>畫面長這樣</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*I0RuFYlSzaIJrwu8fd_Dsw.png" /><figcaption>Jordan 有夠燒!!!!!!!!!!!!!!!!!!!!!</figcaption></figure><p>用到的功能:</p><ol><li>UISegmentedControl 選擇鞋子</li><li>UIImageView 顯示鞋子圖片</li><li>UILabel顯示金額、顯示文字</li><li>UIStepper 要付的金額</li><li>UIButton 購買按鈕</li></ol><p>能觸發的IBAction有</p><ol><li>點選UISegmentedControl 會更新圖片及價格</li><li>點選UIStepper 會修正數量及總金額</li><li>點選UIButton 可以 看有沒有買到</li></ol><p>來看看操作吧</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*NsZOpMI4b0ovtn8-8VSHlQ.gif" /></figure><p><strong><em>更新圖片及價格</em></strong></p><pre><br>var image = [&quot;Air Jordan 1&quot;,<br>                 &quot;Air Jordan 2&quot;,<br>                 &quot;Air Jordan 3&quot;,<br>                 &quot;Air Jordan 4&quot;,<br>                 &quot;Air Jordan 5&quot;,<br>                 &quot;Air Jordan 6&quot;]<br> var price = [&quot;5500&quot;,<br>              &quot;5600&quot;,<br>              &quot;6050&quot;,<br>              &quot;8505&quot;,<br>              &quot;3195&quot;,<br>              &quot;7020&quot;]</pre><pre><a href="http://twitter.com/IBAction">@IBAction</a> func changeSegmentedControl(_ sender: UISegmentedControl) {<br>        let selectNumber = sender.selectedSegmentIndex<br>        changeImage(number: selectNumber)<br>    }</pre><pre>//點選segmentedControl 異動圖片及價錢<br>    func changeImage(number: Int) {<br>        shoeImage.image = UIImage(named: image[number])<br>        shoePrice.text = price[number]<br>        //重置已輸入的金額<br>        restart()<br>    }</pre><p>UIStepper 會修正數量及總金額</p><pre>//價錢數量<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var thousandQty: UILabel!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var fiveHunderQty: UILabel!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var oneHunderQty: UILabel!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var fiftyQty: UILabel!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var tenQty: UILabel!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var fiveQty: UILabel!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var totalPrice: UILabel!<br>    <br>    //價格加減功能<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var thousadnStepper: UIStepper!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var fiveHunderStepper: UIStepper!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var oneHunderStepper: UIStepper!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var fiftyStepper: UIStepper!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var tenStepper: UIStepper!<br>    <a href="http://twitter.com/IBOutlet">@IBOutlet</a> weak var fiveStepper: UIStepper!</pre><pre>    //點增加金額 觸發點<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func changeStepper(_ sender: UIStepper) {<br>        //接值動作<br>        thousandQtyNumber = Int(thousadnStepper.value)<br>        fiveHunderQtyNumber = Int(fiveHunderStepper.value)<br>        oneHunderQtyNumber = Int(oneHunderStepper.value)<br>        fiftyQtyNumber = Int(fiftyStepper.value)<br>        tenQtyNumber = Int(tenStepper.value)<br>        fiveQtyNumber = Int(fiveStepper.value)<br>        //顯示於label (String = Int)<br>        thousandQty.text = &quot;\(thousandQtyNumber)&quot;<br>        fiveHunderQty.text = &quot;\(fiveHunderQtyNumber)&quot;<br>        oneHunderQty.text = &quot;\(oneHunderQtyNumber)&quot;<br>        fiftyQty.text = &quot;\(fiftyQtyNumber)&quot;<br>        tenQty.text = &quot;\(tenQtyNumber)&quot;<br>        fiveQty.text = &quot;\(fiveQtyNumber)&quot;<br>        //加總動作<br>        sumTotal()<br>    }</pre><pre>//計算總金額<br>    func sumTotal() {<br>        let total = thousandQtyNumber*1000 + fiveHunderQtyNumber*500 + oneHunderQtyNumber*100 + fiftyQtyNumber*50<br>                    + tenQtyNumber*10 + fiveQtyNumber*5<br>        totalPrice.text = &quot;\(total)&quot;<br>    }</pre><p><strong><em>購買按鈕</em></strong></p><pre>//購買按鈕 觸發點<br>    <a href="http://twitter.com/IBAction">@IBAction</a> func buy(_ sender: UIButton) {<br>        //原價 shoePirce.text<br>        //已付金額 total.text<br>        if shoePrice.text != nil &amp;&amp; totalPrice.text != nil {<br>            if totalPrice.text == &quot;\(shoePrice.text!)&quot; {<br>                print(&quot;買成功&quot;)<br>                alert(status:1)<br>                //如果購買成功，會跳下一個商品(若是最後一個，會再跳回去第一個)<br>                var number = Segmen.selectedSegmentIndex<br>                var nextNumber : Int<br>                if number == image.count - 1 {<br>                    nextNumber = 0<br>                } else {<br>                    nextNumber = Segmen.selectedSegmentIndex + 1<br>                }<br>                Segmen.selectedSegmentIndex = nextNumber<br>                changeImage(number: nextNumber)<br>                <br>                //changeSegmentedControl()<br>            }   else if totalPrice.text! &lt; &quot;\(shoePrice.text!)&quot; {<br>                alert(status:2)<br>            } else {<br>                alert(status:3)<br>            }<br>            <br>        }<br>    }</pre><pre>//通知訊息<br>    func alert(status: Int) {<br>        var title : String<br>        var message : String<br>        switch status {<br>            case 1 :<br>                title = &quot;成功!!&quot;<br>                message = &quot;購買成功囉!!!&quot;<br>            case 2 :<br>                title = &quot;失敗!!&quot;<br>                message = &quot;錢不夠喔~~&quot;<br>            default:<br>                title = &quot;注意!!&quot;<br>                message = &quot;拍謝不能找錢TAT&quot;<br>        }<br>        //print(message)<br>        //本體<br>        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)<br>        //按鈕<br>        let okAction = UIAlertAction(title: &quot;OK&quot;, style: .default) { (okAction) in<br>            alert.dismiss(animated: true, completion: nil)<br>        }<br>        //將按鈕加入本體<br>        alert.addAction(okAction)<br>        //persend出來<br>        present(alert,animated: true,completion: nil)<br>    }</pre><p>操作流程</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*NsZOpMI4b0ovtn8-8VSHlQ.gif" /></figure><p>附上我的GitHub</p><p><a href="https://github.com/carlton0115354/buyShoe">GitHub - carlton0115354/buyShoe</a></p><p>ps: 圖片皆是google，也只用在自己Demo部分，沒有其他用途，謝謝。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7adeb889751" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E4%BE%86%E8%B2%B7%E9%9B%99%E9%9E%8B%E5%AD%90%E5%90%A7-f7adeb889751">來買雙鞋子吧!!</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[計算BMI app]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E8%A8%88%E7%AE%97bmi-app-1ecb5d834f3d?source=rss-3a98f40e510c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ecb5d834f3d</guid>
            <dc:creator><![CDATA[朱家成]]></dc:creator>
            <pubDate>Sat, 26 Mar 2022 05:41:41 GMT</pubDate>
            <atom:updated>2022-03-26T09:20:52.919Z</atom:updated>
            <content:encoded><![CDATA[<p>現在生活越來越多人在乎完美身材了，也越吃越清淡健康了</p><p>當然會越來越需要計算BMI的工具</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*kHbJIRwbHrjZxO9nfaHyaQ.gif" /></figure><pre>//用來計算BMI值<a href="http://twitter.com/IBAction"><br>@IBAction</a> func RUN(_ sender: Any) {<br>        if let heightText = heightTextField.text,<br>           let weightText = wigthTextField.text,<br>           let height = Double(heightText),<br>           let weight = Double(weightText) {<br>            let heightMeter = height / 100<br>            let bmi: Double = weight / (heightMeter * heightMeter)<br>            BMI.text = String(format: &quot;%.1f&quot;, bmi)<br>    }</pre><p>附上GitHub</p><p><a href="https://github.com/carlton0115354/BMI">GitHub - carlton0115354/BMI</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ecb5d834f3d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E8%A8%88%E7%AE%97bmi-app-1ecb5d834f3d">計算BMI app</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>