<?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 Tai on Medium]]></title>
        <description><![CDATA[Stories by Tai on Medium]]></description>
        <link>https://medium.com/@taiyujourwd?source=rss-3d26c15dc7a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YGN6t1IJ4QMOUCbKtNQAbQ.png</url>
            <title>Stories by Tai on Medium</title>
            <link>https://medium.com/@taiyujourwd?source=rss-3d26c15dc7a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 04:54:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@taiyujourwd/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[#11 研究 Segmented Control、Page Control、Button 功能及用法]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/11-%E7%A0%94%E7%A9%B6-segmented-control-page-control-button-%E5%8A%9F%E8%83%BD%E5%8F%8A%E7%94%A8%E6%B3%95-2a84d683d460?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a84d683d460</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Sun, 20 Nov 2022 04:42:22 GMT</pubDate>
            <atom:updated>2022-11-20T10:26:59.067Z</atom:updated>
            <content:encoded><![CDATA[<p>Segmented Control、Page Control、Button這三個元件在APP介面是很常使用到的元件，主要可以用來控制畫面中圖片切換，下面利用3個元件及圖片示範～</p><ol><li>在View Controller中建立圖片及這個3個件<br>(1) 拉一個Image View及Scroll View，在Asset放入5張圖片<br>(2) 2個Button的Image屬性左邊設成arrowtriangle.backward.fill，右邊的Image設成arrowtriangle.right.fill<br>(3) 放置Segmented Control及Page Control<br>(4) 拉好元件的@IBOutlet</li></ol><pre>    @IBOutlet weak var pageControl: UIPageControl! <br>    @IBOutlet weak var scrollView: UIScrollView! <br>    @IBOutlet weak var segmentedControl: UISegmentedControl!<br>    @IBOutlet weak var rightButton: UIButton! <br>    @IBOutlet weak var leftButton: UIButton! </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*6gKAwpHccRII76XVeDybEw.png" /></figure><p>2. 手機可以直接滑動畫面換圖，所以需要透過Scroll View的delegate同步Button、Segmented Control、Page Control狀態</p><pre>//滑動Scroll View圖片時，透過delegate同步button,segmented control,page control<br>extension ViewController: UIScrollViewDelegate {<br>    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {<br><br>        let page = Int(scrollView.contentOffset.x / scrollView.bounds.width)<br><br>        pageControl.currentPage = page<br>        segmentedControl.selectedSegmentIndex = page<br><br>        buttonState(page)<br>    }<br>}</pre><p>3. 宣告2個函數來改變Button、Segmented Control的狀態</p><pre>    func buttonState(_ ePage: Int) {<br>        if ePage == 0 {<br>            rightButton.isEnabled = true<br>            leftButton.isEnabled = false<br>        } else if ePage == 4 {<br>            rightButton.isEnabled = false<br>            leftButton.isEnabled = true<br>        } else {<br>            rightButton.isEnabled = true<br>            leftButton.isEnabled = true<br>        }<br>    }<br>    <br>    func pageSegmentedControlState(_ eSender: UIButton, _ ePage: Int) {<br>        <br>        if eSender.restorationIdentifier! == &quot;right&quot; {<br>            segmentedControl.selectedSegmentIndex = ePage + 1<br>            pageControl.currentPage = ePage + 1<br>        } else {<br>            segmentedControl.selectedSegmentIndex = ePage - 1<br>            pageControl.currentPage = ePage - 1<br>        }<br>    }</pre><p>4. 設置Button的功能，程式碼如下：</p><pre>    //往右滑動<br>    @IBAction func rightButtonAction(_ sender: UIButton) {<br><br>        //當圖片為左邊最後一張時，向左的鈕為disable，故往右時先將往左鈕設為true<br>        leftButton.isEnabled = true<br><br>        //計算圖片為第幾張<br>        let page = Int(scrollView.contentOffset.x / scrollView.bounds.width)<br>        <br>        if page &lt;= 4 {<br>            //設置顯示的圖片<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page + 1)<br>        }<br>        //圖片為右邊最後一張，將往右鈕設為disable<br>        if page == 3 {<br>            rightButton.isEnabled = false<br>        }<br>        //連動Segmented Control<br>        pageSegmentedControlState(sender, page)<br>    }<br>    <br>    //往左滑動<br>    @IBAction func leftButtonAction(_ sender: UIButton) {<br><br>        //當圖片為右邊最後一張時，向右的鈕為disable，故往左時先將往右鈕設為true<br>        rightButton.isEnabled = true<br>        //計算圖片為第幾張<br>        let page = Int(scrollView.contentOffset.x / scrollView.bounds.width)<br>        <br>        if page &gt;= 0 {<br>            //設置顯示的圖片<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page - 1)<br>        }<br>        //圖片為左邊最後一張，將往左鈕設為disable<br>        if page == 1 {<br>            leftButton.isEnabled = false<br>        }<br>        //連動Segmented Control<br>        pageSegmentedControlState(sender, page)<br>    }<br><br></pre><p>5. 設置Segmented Control功能，程式碼如下：</p><pre>@IBAction func segmentedAction(_ sender: Any) {<br>        <br>        //Segmented Control選擇的Index<br>        let page = segmentedControl.selectedSegmentIndex<br><br>        //設置Page Control的狀態及顯示第幾張圖片<br>        pageControl.currentPage = page<br>        <br>        //以Index判斷並設置Scroll View圖片<br>        if page == 0 {<br>            scrollView.contentOffset.x = 0<br>        } else if page == 1 {<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page)<br>        } else if page == 2 {<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page)<br>        } else if page == 3 {<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page)<br>        } else if page == 4 {<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page)<br>        }<br>        <br>        //改變Button狀態<br>        buttonState(page)<br>        <br>    }</pre><p>6. 設定Page Control的功能，有個小特點說明一下，Page Control不管是往左點或是往右點，都只會一張一張的改變，無法呈現跳躍的方式，程式碼如下：</p><pre>    @IBAction func pageContrlAction(_ sender: Any) {<br>        //獲得目前在第幾張圖<br>        let page = pageControl.currentPage<br>        <br>        //設定Segmented Control在第幾張<br>        segmentedControl.selectedSegmentIndex = page<br>        <br>        //根據Page Control設置Scroll View圖片<br>        if page == 0 {<br>            scrollView.contentOffset.x = 0<br>        } else if page == 1 {<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page)<br>        } else if page == 2 {<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page)<br>        } else if page == 3 {<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page)<br>        } else if page == 4 {<br>            scrollView.contentOffset.x = scrollView.bounds.width * CGFloat(page)<br>        }<br>        <br>        //改變Button狀態<br>        buttonState(page)<br>    }</pre><p>以上為這3個元件主要功能分享，謝謝觀賞～～</p><p>成品動圖：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*mocihLAqS0hRXUydNxKQrw.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a84d683d460" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/11-%E7%A0%94%E7%A9%B6-segmented-control-page-control-button-%E5%8A%9F%E8%83%BD%E5%8F%8A%E7%94%A8%E6%B3%95-2a84d683d460">#11 研究 Segmented Control、Page Control、Button 功能及用法</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[#10 Instagram照片牆]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/10-instagram%E7%85%A7%E7%89%87%E7%89%86-4e056a40bb8f?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e056a40bb8f</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 12:04:38 GMT</pubDate>
            <atom:updated>2022-11-19T15:42:45.217Z</atom:updated>
            <content:encoded><![CDATA[<p>IG是現在必備的社交軟體，在個人資訊會有一個PO文圖片的照片牆，今天利用API及JOSON模擬製作照片牆，建置步驟如下：</p><p>由於IG官方未提供下載PO文圖的API，故利用網路上有人研究出來的方式抓取JSON檔後，放置在Xcode左邊的檔案樹狀圖區下，再使用程式碼讀取JSON檔內容。</p><p>使用下方API抓取IG的PO文圖片及文字檔(下方&quot;iambaijiji”可以置換成想要抓取的帳號)：</p><p><a href="https://www.instagram.com/iambaijiji/?__a=1&amp;__d=dis">https://www.instagram.com/iambaijiji/?__a=1&amp;__d=dis</a></p><ol><li>在編輯區內新增Collection View Controller，IG的個人檔案畫面中，最上方是個人檔案的部份，需在Collection View Controller將Accessories這個項目打勾，顯示表頭。</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*Sud6WMzLY1a4X8I6BAezJg.png" /></figure><p>2. 新增1個Table View Controller，並拉Collection View Cell連線給這個Controller用來顯示圖片詳細內容，並完成2個Controller中要呈現畫面的元件</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zyxjtRqhjoUyu9AQEkGCWg.png" /></figure><p>3. 接下來解析JSON，並將下載下來的JSON檔放置在Xcode左側的樹狀圖區，撰寫程式碼讀取</p><p>JSON解析檔：</p><pre>struct IGResponse: Codable {<br>    var graphql: Graphql<br>    struct Graphql: Codable {<br>        var user: User<br>        struct User: Codable {<br>            var biography: String //作者簡介<br>            var external_url: URL //白吉FB首頁<br>            var edge_followed_by: EdgeFollowedBy //粉絲追蹤數<br>            struct EdgeFollowedBy: Codable {<br>                var count: Int //粉絲追蹤數<br>            }<br>            var edge_follow: EdgeFollow<br>            struct EdgeFollow: Codable {<br>                var count: Int<br>            }<br>            var full_name: String //大頭照下方名字<br>            var category_name: String //名字下方類型<br>            var profile_pic_url: URL //個人檔案大頭照<br>            var username: String //最上方IG使用者名字<br>            var edge_felix_video_timeline: VideoDetail //影片貼文資訊<br>            struct VideoDetail: Codable {<br>                var count: Int //影片貼文數<br>                var page_info: VideoPageInfo //影片貼文是否有下一頁<br>                struct VideoPageInfo: Codable {<br>                    var has_next_page: Bool<br>                    var end_cursor: String<br>                }<br>                var edges: [VideoEdges]<br>                struct VideoEdges: Codable {<br>                    var node: VideoNode<br>                    struct VideoNode: Codable {<br>                        var video_url: URL //影片url<br>                        var edge_media_to_caption: EdgeMediaToCaption //影片貼文文字<br>                        struct EdgeMediaToCaption: Codable {<br>                            var edges: [VideoEdgeNode]<br>                            struct VideoEdgeNode: Codable {<br>                                var node: Text<br><br>                                struct Text: Codable {<br>                                    var text: String //影片貼文<br>                                }<br>                            }<br>                        }<br>                        var edge_media_to_comment: EdgeMediaToComment //影片貼文留言數<br>                        struct EdgeMediaToComment: Codable {<br>                            var count: Int //影片貼文留言數<br>                        }<br>                        var edge_liked_by: EdgeLikedBy<br>                        struct EdgeLikedBy: Codable {<br>                            var count: Int //影片貼文按讚數<br>                        }<br>                    }<br>                }<br>            }<br>            var edge_owner_to_timeline_media: PhotoDetail //照片貼文資訊<br>            struct PhotoDetail: Codable {<br>                var count: Int //照片貼文數<br>                var page_info: PhotoPageInfo //照片貼文是否有下一頁<br>                struct PhotoPageInfo: Codable {<br>                    var has_next_page: Bool<br>                    var end_cursor: String<br>                }<br>                var edges: [Edges]<br>                struct Edges: Codable {<br>                    var node: PhotoNode<br>                    struct PhotoNode: Codable {<br>                        var display_url: URL //照片貼文圖片<br>                        var edge_media_to_caption: EdgeMediaToCaption //照片貼文文字<br>                        struct EdgeMediaToCaption: Codable {<br>                            var edges: [PhotoEdges]<br>                            struct PhotoEdges: Codable {<br>                                var node: PhotoEdgesNode<br>                                struct PhotoEdgesNode: Codable {<br>                                    var text: String //照片貼文文字<br>                                }<br>                            }<br>                        }<br>                        var edge_media_to_comment: EdgeMediaToComment<br>                        struct EdgeMediaToComment: Codable {<br>                            var count: Int //圖片貼文留言數<br>                        }<br>                        var edge_liked_by: EdgeLikedBy<br>                        struct EdgeLikedBy: Codable {<br>                            var count: Int //圖片貼文安讚數<br>                        }<br>                    }<br>                }<br>            }<br><br>        }<br>    }<br>}</pre><p>讀取JSON檔的程式碼(iambaijiji.json)：</p><pre>//在ViewDidLoad()中呼叫<br>let searchResponse: IGResponse = load(&quot;iambaijiji&quot;)<br><br>//在第一頁的類別檔中的函數<br>func load&lt;T: Decodable&gt;(_ filename: String) -&gt; T {<br>        let data: Data<br>        <br>        guard let file = Bundle.main.url(/service/forresource: filename, withExtension: &quot;json&quot;) else {<br>            fatalError(&quot;Couldn&#39;t find \(filename) in main bundle.&quot;)<br>        }<br>        do {<br>            data = try Data(contentsOf: file)<br>        } catch {<br>            fatalError(&quot;Couldn&#39;t load \(filename) in main bundle:\n\(error)&quot;)<br>        }<br>        do {<br>            let decoder = JSONDecoder()<br>            return try decoder.decode(T.self, from: data)<br>        } catch {<br>            fatalError(&quot;Couldn&#39;t parse \(filename) as \(T.self):\n\(error)&quot;)<br>        }<br>    }</pre><p>4. 設定Cell的大小及間距</p><pre>func configureCellSize() {<br>        let itemSpace: Double = 4<br>        let columnCount: Double = 3<br>        let flowLayout = collectionViewLayout as? UICollectionViewFlowLayout<br>        let width = floor((collectionView.bounds.width - itemSpace * (columnCount - 1)) / columnCount)<br>        flowLayout?.itemSize = CGSize(width: width, height: width)<br>        flowLayout?.estimatedItemSize = .zero<br>        flowLayout?.minimumInteritemSpacing = itemSpace<br>        flowLayout?.minimumLineSpacing = itemSpace<br>    }</pre><p>5. 自定義Collection View Cell後，在第一頁將拉@IBSegueAction用來點擊Cell時將資料傳給第二頁</p><pre>@IBSegueAction func showDetailSegue(_ coder: NSCoder) -&gt; DetailTableViewController? {<br>        guard let row = collectionView.indexPathsForSelectedItems?.first?.row else { return nil}<br>        return DetailTableViewController(coder: coder, userInfo: userInfo!, indexPath: row)<br>                <br>    }</pre><p>6. 第二頁定義好接收的變數</p><pre>let searchResponse: String<br>    let postInfo:IGResponse.Graphql.User.PhotoDetail<br>    let indexPath:Int<br>    let userImageUrl:URL<br>    let userAcount:String<br>    <br>    init?(coder:NSCoder,userInfo:IGResponse, indexPath:Int ) {<br>        self.postInfo = userInfo.graphql.user.edge_owner_to_timeline_media<br>        self.indexPath = indexPath<br>        self.userImageUrl = userInfo.graphql.user.profile_pic_url<br>        self.userAcount = userInfo.graphql.user.username<br>        self.searchResponse = userInfo.graphql.user.full_name<br>        super.init(coder: coder)<br>    }</pre><p>7. 進入第二頁時，想直接跳到第一頁點選的圖片</p><pre>//詳細頁面跳到所選的圖片位置<br>    var isShow = false<br>    override func viewDidLayoutSubviews() {<br>        if isShow == false{<br>            tableView.scrollToRow(at: IndexPath(item: indexPath, section: 0), at: .top, animated: true)<br>            isShow = true<br>            <br>        }<br>    }</pre><p>8. 自己製作返回上一頁的按鈕( &lt; )</p><pre>@IBAction func backToPrepage(_ sender: Any) {<br>        self.dismiss(animated: true)<br>}</pre><p>以上就是使用Collection View製作圖片牆主要步驟～收工！回家吃飯～～～</p><p>完成圖：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*qCRyGI8F3maIWnXwJ3M-qQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e056a40bb8f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/10-instagram%E7%85%A7%E7%89%87%E7%89%86-4e056a40bb8f">#10 Instagram照片牆</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[#9 用RESTful API來訂杯珍奶喝吧！Part-6-手機定位、分店位址及地圖]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/9-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-6-%E6%89%8B%E6%A9%9F%E5%AE%9A%E4%BD%8D-%E5%88%86%E5%BA%97%E4%BD%8D%E5%9D%80%E5%8F%8A%E5%9C%B0%E5%9C%96-93667059b8ba?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/93667059b8ba</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 10:12:40 GMT</pubDate>
            <atom:updated>2022-11-22T07:29:32.365Z</atom:updated>
            <content:encoded><![CDATA[<p>選好想喝的飲料後，想知道最近的分店離我們所在的位置有多遠，也免驚～</p><p>可以透過Google Map API定位我們現在所在位置，列出最近的幾間分店，方便購買飲及拿取飲料哦～</p><ol><li>首先在Storyboard中使用Table View Controller、MKMapView、Label建立我們要的頁面</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*tC8kCPjv0pfiCuLx_CjDIQ.png" /></figure><p>2. 地圖頁面型別中import MapKit及CoreLocation這2個framework，將型別Conform to Protocol: CLLocationManagerDelegate，設定locationManager的delegate</p><pre>class StoreInfoTableViewController: UITableViewController, CLLocationManagerDelegate {<br><br>locationManger?.delegate = self</pre><p>3. 在APP設定頁面Info設定使用者位置的存取政策，這一定要設置，不然就是唯一閃退</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OLiIO8A6Ficu-GTlEUgJvA.png" /></figure><p>4. 撰寫手機定位Code</p><pre>   func fetchUserLocation() {<br>        //定位<br>        locationManger = CLLocationManager() //指派locationManger取得CLLocationManager()功能<br>        locationManger?.requestWhenInUseAuthorization() //尋求使用者是否授權APP得知位置<br>        locationManger?.delegate = self //若是user有移動，可以將透過delegate知道位置顯示<br>        locationManger?.desiredAccuracy = kCLLocationAccuracyBest //user位置追蹤精確程度，設置成最精確位置<br>        locationManger?.activityType = .automotiveNavigation //設定使用者的位置模式，手機會去依照不同設定做不同的電力控制<br>        locationManger?.startUpdatingLocation() //user有移動會啟動追蹤位置(CLLocationManagerDelegate)<br><br>        //授權同意後取得使用者位置後指派給hereForNow<br>        if let hereForNow = locationManger?.location?.coordinate {<br>            let scaleForX: CLLocationDegrees = 0.01 //精度緯度設置為0.01<br>            let scaleForY: CLLocationDegrees = 0.01<br><br>            //指派span為MKCoordinateSpan後加入精度緯度的比例<br>            let span: MKCoordinateSpan = MKCoordinateSpan(latitudeDelta: scaleForY, longitudeDelta: scaleForX)<br>            //指派regineForNow為MKCoordinateRegion加入現在的user位置，顯示比例為span<br>            let _ = MKCoordinateRegion(center: hereForNow, span: span)<br>        }<br>    }</pre><p>5. 有了定位點後，依此點透過locationManager的delegate呼叫Google Map API找出1000m內的分店</p><pre>   func fetchStoreInfo(_ lat: Double, _ lng: Double) {<br>        <br>        let orgUrl = &quot;https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=\(lat),\(lng)&amp;radius=1000&amp;keyword=春水堂&amp;language=zh-TW&amp;key=Your APK_KEY&quot;<br>        //網址有中文字，需進行編碼<br>        let strUrl = orgUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)<br>        let request = URLRequest(url: URL(string: strUrl!)!)<br>        URLSession.shared.dataTask(with: request) { data, response, error in<br>            if let data {<br>                do {<br>                    let decoder = JSONDecoder()<br>                    let storeInfoDecode = try decoder.decode(StoreInfo.self, from: data)<br>                    self.storeInfo = []<br>                    if storeInfoDecode.results.count != 0 {<br>                        for i in 0...(storeInfoDecode.results.count - 1){<br>                            self.storeInfo.append(storeInfoDecode.results[i])<br>                        }<br>                        DispatchQueue.main.async {<br>                            self.tableView.reloadData()<br>                        }<br>                        if self.storeInfo.count == 0 {<br>                            let controller = UIAlertController(title: &quot;店家訊息通知&quot;, message: &quot;您所在附近沒有店家&quot;, preferredStyle: .alert)<br>                            let okAction = UIAlertAction(title: &quot;好的&quot;, style: .default)<br>                            controller.addAction(okAction)<br>                            self.present(controller, animated: true)<br>                        }<br>                    }<br>                } catch {<br>                    print(error)<br>                }<br>            }<br>        }.resume()<br>    }</pre><p>6. 有了以上2個資料後即可描繪地圖，將定位點及分店位址Marker在地圖上</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*hmVTY2dcYOhDgq8eiYQzRA.png" /></figure><p>以上是這個APP小故事，謝謝各位觀賞到最後～</p><p><a href="https://medium.com/@taiyujou133/4-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-1-11acd2e6e21">#4 用RESTful API來訂杯珍奶喝吧！Part-1-畫面及功能簡介 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/e465cd063b70">#5 用RESTful API來訂杯珍奶喝吧！Part-2-Web官網整合介紹 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/6-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-3-e8bfbffb276e">#6 用RESTful API來訂杯珍奶喝吧！Part-3-menu呈現及banner輪播 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/7-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-4-%E8%A8%82%E5%96%AE%E4%B8%8A%E5%82%B3%E5%8F%8A%E6%9F%A5%E8%A9%A2-47259a618472">#7 用RESTful API來訂杯珍奶喝吧！Part-4-訂單上傳及查詢 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/8-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-5-%E8%A8%82%E5%96%AE%E4%BF%AE%E6%94%B9%E5%8F%8A%E5%88%AA%E9%99%A4-47f81d3c0cee">#8 用RESTful API來訂杯珍奶喝吧！Part-5-訂單修改及刪除 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93667059b8ba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/9-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-6-%E6%89%8B%E6%A9%9F%E5%AE%9A%E4%BD%8D-%E5%88%86%E5%BA%97%E4%BD%8D%E5%9D%80%E5%8F%8A%E5%9C%B0%E5%9C%96-93667059b8ba">#9 用RESTful API來訂杯珍奶喝吧！Part-6-手機定位、分店位址及地圖</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[#8 用RESTful API來訂杯珍奶喝吧！Part-5-訂單修改及刪除]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/8-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-5-%E8%A8%82%E5%96%AE%E4%BF%AE%E6%94%B9%E5%8F%8A%E5%88%AA%E9%99%A4-47f81d3c0cee?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/47f81d3c0cee</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Thu, 17 Nov 2022 15:04:16 GMT</pubDate>
            <atom:updated>2022-11-21T04:22:02.201Z</atom:updated>
            <content:encoded><![CDATA[<p>點完飲料才發現冰塊、甜度、杯數不對，或是根本選錯取餐分店，想要改一下訂的內容，或是低頭看見走樣的身材，覺得良心不安後悔不想喝了～就默默的按一下訂單，進入修改刪除的頁面處理吧～</p><p>先來看看修改訂單是如何建置出來的：</p><ol><li>在Storyboard中設定好修改訂單頁面，並將訂單列表的Cell連線到訂單修改頁面，訂單資訊透過Segue傳送到此頁面顯示</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*sXwbYFkiDXr8sqVljfpjEw.png" /></figure><p>2. 設定好上述的事情後，接著就是解析要做為上傳修改的JSON，並透過RESTful API修改Airtable上OrderList的訂單內容，那要怎麼知道要修改哪筆資料呢？<br>在Airtable創建每筆record時，每筆record帶有一個唯一的id，在上頁訂單列表時就透過API一起下載，Segue一併將id傳到修改頁，在執行修改時帶入id就可以找到要修改的訂單record</p><p>上頁訂單列表的JSON型別：</p><pre>      import Foundation<br>      <br>      struct OrderInfo: Codable {<br>          var id: String //每筆record創建時同時產生的唯一 id，隨Segue傳到下一頁<br>          var createdTime: Date<br>          var fields: Fields<br>          <br>          struct Fields: Codable {<br>              var name: String<br>              var price: Double<br>              var iceDegree: String<br>              var sugarDegree: String<br>              var cupAmount: Int<br>              var comment: String<br>              var userName: String<br>              var userPhone: String<br>              var totalAmount: Int<br>          }<br>      }</pre><p>上傳修改的JSON型別及程式碼：</p><pre>      //JSON解析型別<br>      import Foundation<br><br>      struct UpdateOrderInfo: Codable {<br>          var fields: Fields<br>          <br>          struct Fields: Codable {<br>              var name: String<br>              var price: Int<br>              var iceDegree: String<br>              var sugarDegree: String<br>              var cupAmount: Int<br>              var comment: String<br>              var userName: String<br>              var userPhone: String<br>              var totalAmount: Int<br>              var updateTime: String<br>              var storeName: String<br>          }<br>      }<br><br>      //修改函數<br>      func fetchUpdateOrderInfo(name: String, price: Int, iceDegree: String, sugarDegree: String, cupAmount: Int, comment: String, userName: String, userPhone: String, updateTime: String, id: String, storeName: String) {<br>        <br>        //計算總金額<br>        let totalAmount = price * cupAmount<br>        <br>        //API最後代入的id即為每筆record的唯一識別碼，有它才可以正確的修改到對的record<br>        let url = URL(string: &quot;https://api.airtable.com/v0/appHy2q9FOUrGGhqS/OrderList/\(id)&quot;)!<br>        let apiKey = &quot;Your API_KEY&quot;<br>        let httpHeader = &quot;Authorization&quot;<br>        var request = URLRequest(url: url)<br>        request.httpMethod = &quot;PUT&quot; //修改<br>        request.setValue(apiKey, forHTTPHeaderField: httpHeader)<br>        request.setValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)<br>        let encoder = JSONEncoder()<br>        let fieldsData = UpdateOrderInfo.Fields(name: name, price: price, iceDegree: iceDegree, sugarDegree: sugarDegree, cupAmount: cupAmount, comment: comment, userName: userName, userPhone: userPhone, totalAmount: totalAmount, updateTime: updateTime, storeName: storeName)<br>        let uploadData = UpdateOrderInfo(fields: fieldsData)<br>        let data = try? encoder.encode(uploadData)<br>        request.httpBody = data<br>        URLSession.shared.dataTask(with: request) { data, response, error in<br>            if error == nil {<br>                print(&quot;修改成功&quot;)<br>            } else {<br>                print(error ?? &quot;&quot;)<br>            }<br>        }.resume()<br>        <br>        let controller = UIAlertController(title: &quot;修改通知&quot;, message: &quot;己修改完成&quot;, preferredStyle: .alert)<br>        let okAction = UIAlertAction(title: &quot;好的&quot;, style: .default)<br>        controller.addAction(okAction)<br>        self.present(controller, animated: true)<br>    }</pre><p>上述設定就可以輕鬆的修改訂單內容囉～</p><p>刪除的訂單的原理同修改功能，差別在於因為沒有資料要與Airtable溝通，故不需要JSON的解析型別，僅需在API代入record的唯一 id，且request.httpMethod = “DELETE” 即可刪除</p><p>API程式碼：</p><pre>      func fetchDeleteOrderInfo(id: String) {<br>        <br>        //API最後代入的id即為每筆record的唯一識別碼，有它才可以正確的刪除到對的record<br>        let url = URL(string: &quot;https://api.airtable.com/v0/appHy2q9FOUrGGhqS/OrderList/\(id)&quot;)!<br>        let apiKey = &quot;Your API_KEY&quot;<br>        let httpHeader = &quot;Authorization&quot;<br>        var request = URLRequest(url: url)<br>        request.httpMethod = &quot;DELETE&quot; //刪除<br>        request.setValue(apiKey, forHTTPHeaderField: httpHeader)<br>        request.setValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)<br>        URLSession.shared.dataTask(with: request) { data, response, error in<br>            if error == nil {<br>                print(&quot;刪除成功&quot;)<br>            } else {<br>                print(error ?? &quot;&quot;)<br>            }<br>        }.resume()<br>        <br>        let controller = UIAlertController(title: &quot;刪除通知&quot;, message: &quot;己刪除訂單&quot;, preferredStyle: .alert)<br>        let okAction = UIAlertAction(title: &quot;好的&quot;, style: .default)<br>        controller.addAction(okAction)<br>        self.present(controller, animated: true)<br>    }</pre><p>以上就輕鬆的做到修改及刪除訂單的功能了～</p><p>打完收工～訂單功的部份全部介紹完畢，下篇就是透過Google Map API取得分店資訊及使用者定位的功能，人客啊～欲知詳情～下回分解～～～</p><p>關聯文章：</p><p><a href="https://medium.com/@taiyujou133/4-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-1-11acd2e6e21">#4 用RESTful API來訂杯珍奶喝吧！Part-1-畫面及功能簡介 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/e465cd063b70">#5 用RESTful API來訂杯珍奶喝吧！Part-2-Web官網整合介紹 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/6-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-3-e8bfbffb276e">#6 用RESTful API來訂杯珍奶喝吧！Part-3-menu呈現及banner輪播 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/7-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-4-%E8%A8%82%E5%96%AE%E4%B8%8A%E5%82%B3%E5%8F%8A%E6%9F%A5%E8%A9%A2-47259a618472">#7 用RESTful API來訂杯珍奶喝吧！Part-4-訂單上傳及查詢 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47f81d3c0cee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/8-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-5-%E8%A8%82%E5%96%AE%E4%BF%AE%E6%94%B9%E5%8F%8A%E5%88%AA%E9%99%A4-47f81d3c0cee">#8 用RESTful API來訂杯珍奶喝吧！Part-5-訂單修改及刪除</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[#7 用RESTful API來訂杯珍奶喝吧！Part-4-訂單上傳及查詢]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/7-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-4-%E8%A8%82%E5%96%AE%E4%B8%8A%E5%82%B3%E5%8F%8A%E6%9F%A5%E8%A9%A2-47259a618472?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/47259a618472</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Thu, 17 Nov 2022 10:39:34 GMT</pubDate>
            <atom:updated>2022-11-21T04:23:13.944Z</atom:updated>
            <content:encoded><![CDATA[<p>如顆要順利喝到想喝的飲料，那就不能少了這一步-上傳訂單，告知店家您想喝什麼飲料～</p><p>接著就來看看上如何從APP上，將您的想法告訴遠方的飲料店人員您訂了什麼飲品：</p><p>稍早己在Airtable上建立了OrderList這個table用來存訂單的資訊～</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzqqQRvUifvTFRsQ_-KK1A.png" /></figure><ol><li>在Storyboard建立程式訂購飲料頁面，設定好AutoLayout，並將前頁2個menu list的Cell連接到訂購飲料頁面，訂購頁的Content可以選擇使用Static Cells</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*pAjyMIJ7LBNf7-ejCA-X5A.png" /></figure><p>2. 使用者在menu list頁面點選想要訂購的飲料後，透過Segue將資料傳至訂購頁面</p><p>3. 接著，解析上傳JSON資料型別，並寫程式透過RESTful API方式將訂單上傳(POST)，上傳前檢核TextField欄位若為空顯示Alert告知使用者填寫，按下訂購鈕以Alert顯示訊息告知使用杯數及總價，使用確認訂購再以Alert告知訂購完成</p><pre>        //解析上傳JSON的型別<br>        import Foundation<br><br>        struct UpdateOrderInfo: Codable {<br>            var fields: Fields<br>            <br>            struct Fields: Codable {<br>                var name: String<br>                var price: Int<br>                var iceDegree: String<br>                var sugarDegree: String<br>                var cupAmount: Int<br>                var comment: String<br>                var userName: String<br>                var userPhone: String<br>                var totalAmount: Int<br>                var updateTime: String<br>                var storeName: String<br>            }<br>        }<br><br>        //上傳訂單的函數<br>        func uploadOrderInfo(name: String, price: Int, iceDegree: String, sugarDegree: String, cupAmount: Int, comment: String, userName: String, userPhone: String, totalAmount: Int, storeName: String) {<br>        <br>        //計算總金額<br>        self.totalAmount = price * cupAmount<br>        <br>        let url = URL(string: &quot;https://api.airtable.com/v0/appHy2q9FOUrGGhqS/OrderList&quot;)!<br>        let apiKey = &quot;Your API_KEY&quot;<br>        let httpHeader = &quot;Authorization&quot;<br>        var request = URLRequest(url: url)<br>        request.httpMethod = &quot;POST&quot; //新增<br>        request.setValue(apiKey, forHTTPHeaderField: httpHeader)<br>        request.setValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)<br>        let encoder = JSONEncoder()<br>        let fieldsData = UploadOrderData.Fields(name: name, price: price, iceDegree: iceDegree, sugarDegree: sugarDegree, cupAmount: cupAmount, comment: comment, userName: userName, userPhone: userPhone, totalAmount: totalAmount, storeName: storeName)<br>        let uploadData = UploadOrderData.Records(fields: fieldsData)<br>        let data = try? encoder.encode(uploadData)<br>        request.httpBody = data<br>        URLSession.shared.dataTask(with: request) { data, response, error in<br>            if let data {<br>                do {<br>                    let decoder = JSONDecoder()<br>                    let formatter = DateFormatter()<br>                    //自訂時間格式<br>                    formatter.dateFormat = &quot;yyyy-MM-dd&#39;T&#39;HH:mm:ss.SSSZ&quot;<br>                    decoder.dateDecodingStrategy = .formatted(formatter)<br>                    let _ = try decoder.decode(OrderInfo.self, from: data)<br>                } catch {<br>                    print(error)<br>                }<br>            }<br>        }.resume()<br>        <br>        //提示己完成訂購<br>        let controller = UIAlertController(title: &quot;訂購通知&quot;, message: &quot;己完成訂購&quot;, preferredStyle: .alert)<br>        let okAction = UIAlertAction(title: &quot;好的&quot;, style: .default)<br>        controller.addAction(okAction)<br>        self.present(controller, animated: true)<br>    }</pre><p>詢問是否訂購：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*p680SzJ-2jITKDoOSMzJYQ.png" /></figure><p>提示己訂購完成：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*AQZw9CGzXGzsSsUqthgqtw.png" /></figure><p>確認Airtable的OrderList數到上傳的訂單：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5EIMaxxItcf9jZAKXzu0Bg.png" /></figure><p>接著來說說訂單查詢的部份囉～</p><ol><li>在Storyboard中設定好&quot;訂單列表頁面&quot;</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*HYPaZmQpmlWruKSuOSHiLQ.png" /></figure><p>2. 回到menu list的頁面，右上角新增&quot;訂單&quot;按鈕，並將Button連接到&quot;訂單列表頁面&quot;</p><p>3. 按下&quot;訂單&quot;鈕後，透過API下載訂單資料，下載完成後顯示在APP畫面中</p><pre>      //解析JSON型別<br>      import Foundation<br>      <br>      struct OrderInfo: Codable {<br>          var id: String<br>          var createdTime: Date<br>          var fields: Fields<br>          <br>          struct Fields: Codable {<br>              var name: String<br>              var price: Double<br>              var iceDegree: String<br>              var sugarDegree: String<br>              var cupAmount: Int<br>              var comment: String<br>              var userName: String<br>              var userPhone: String<br>              var totalAmount: Int<br>          }<br>      }<br>      <br>      //下載訂單資料函數<br>      func fetchOrderInfoList() {<br>        //網址中sort那串字是API排序的方式，預設ASC<br>        //sort%5B0%5D%5Bfield%5D=createdTime&amp;sort%5B0%5D%5Bdirection%5D=desc依據創建時間由新而舊排序<br>        let url = URL(string: &quot;https://api.airtable.com/v0/appHy2q9FOUrGGhqS/OrderList?sort%5B0%5D%5Bfield%5D=createdTime&amp;sort%5B0%5D%5Bdirection%5D=desc&quot;)!<br>        let apiKey = &quot;Your API_Key&quot;<br>        let httpHeader = &quot;Authorization&quot;<br>        var request = URLRequest(url: url)<br>        request.httpMethod = &quot;GET&quot; //下載<br>        request.setValue(apiKey, forHTTPHeaderField: httpHeader)<br>        request.setValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)<br>        URLSession.shared.dataTask(with: request) { data, response, error in<br>            if let data {<br>                do {<br>                    let decoder = JSONDecoder()<br>                    let formatter = DateFormatter()<br>                    formatter.dateFormat = &quot;yyyy-MM-dd&#39;T&#39;HH:mm:ss.SSSZ&quot;<br>                    decoder.dateDecodingStrategy = .formatted(formatter)<br>                    let orderInfo = try decoder.decode(LoadOrderInfoList.self, from: data)<br>                    if orderInfo.records.count &gt; 0 {<br>                        self.loadOrderInfoList = []<br>                        for i in 0...(orderInfo.records.count - 1){<br>                            self.loadOrderInfoList.append(orderInfo.records[i])<br>                        }<br>                        <br>                        let controller = UIAlertController(title: &quot;使用通知&quot;, message: &quot;點選訂單，可進入修改刪除頁面&quot;, preferredStyle: .alert)<br>                        let okAction = UIAlertAction(title: &quot;好的&quot;, style: .default)<br>                        controller.addAction(okAction)<br>                        self.present(controller, animated: true)<br>                    } else {<br>                        let controller = UIAlertController(title: &quot;訊息通知&quot;, message: &quot;目前尚無訂單&quot;, preferredStyle: .alert)<br>                        let okAction = UIAlertAction(title: &quot;好的&quot;, style: .default)<br>                        controller.addAction(okAction)<br>                        self.present(controller, animated: true)<br>                    }<br>                    DispatchQueue.main.async {<br>                        self.tableView.reloadData()<br>                    }<br>                } catch {<br>                    print(error)<br>                }<br>            }<br>        }.resume()<br>    }</pre><p>呈現在APP的畫面：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*dgXYcv82vycucJcdIW-cuA.png" /></figure><p>以上就是訂單上傳及查詢建置內容，謝謝觀賞～</p><p>相關聯結：</p><p><a href="https://medium.com/@taiyujou133/4-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-1-11acd2e6e21">#4 用RESTful API來訂杯珍奶喝吧！Part-1-畫面及功能簡介 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/e465cd063b70">#5 用RESTful API來訂杯珍奶喝吧！Part-2-Web官網整合介紹 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/6-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-3-e8bfbffb276e">#6 用RESTful API來訂杯珍奶喝吧！Part-3-menu呈現及banner輪播 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/8-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-5-%E8%A8%82%E5%96%AE%E4%BF%AE%E6%94%B9%E5%8F%8A%E5%88%AA%E9%99%A4-47f81d3c0cee">#8 用RESTful API來訂杯珍奶喝吧！Part-5-訂單修改及刪除 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47259a618472" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/7-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-4-%E8%A8%82%E5%96%AE%E4%B8%8A%E5%82%B3%E5%8F%8A%E6%9F%A5%E8%A9%A2-47259a618472">#7 用RESTful API來訂杯珍奶喝吧！Part-4-訂單上傳及查詢</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[#6 用RESTful API來訂杯珍奶喝吧！Part-3-menu呈現及banner輪播]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/6-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-3-e8bfbffb276e?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8bfbffb276e</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Wed, 16 Nov 2022 15:41:48 GMT</pubDate>
            <atom:updated>2022-11-21T04:24:27.412Z</atom:updated>
            <content:encoded><![CDATA[<p>接下來是這個APP的重頭戲，建置飲料menu、訂單的新增、查詢、修改、刪除功能，最花時間也是最重要的部份～請客位看倌耐心欣賞～</p><p>先來說說飲料menu建置的部份：</p><p>使用Airtable當成遠端資料庫，將飲料的相關資訊建置在其上，使用RESTful API取得資料及上傳資料</p><ol><li>在Airtable上建立2個表單-DrinkingMenuList、OrderList</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*tXnSFTUH0rdjyq-qhgl1Pg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rUuf8n811seWFrhx5LRvEQ.png" /></figure><p>2. 在Xcode中新增View Controller，加入Navigation Controller及Tab Bar Controller，將Tab Bar項目改成&quot;訂飲料&quot;及購物車圖示</p><p>3. 在上面第2點新增的View Controller中放置1個Collection View建置輪播banner、2個Container View、1個Segmented Control及2個Table View Controller製作訂單列表(Segmented Control是用來切換冷熱飲List)，並設定好AutoLayout</p><p>4. 使用Segmented Control及2個Container View切換冷熱飲畫面，先拉好2個Container View的@IBOutlet Collection及Segmented Control的@IBAction，再來寫切換的function</p><p>節錄程式碼如下：</p><pre>    //將2個Container View拉到@IBOutlet Collection<br>    @IBOutlet var drinkingContainerViews: [UIView]!<br>    <br>    //Segmented Control的@IBAction<br>    @IBAction func segmentedControlAction(_ sender: UISegmentedControl) {<br>        //切換冷熱飲<br>        drinkingContainerViewsChange()<br>        <br>    }<br><br>    //切換冷熱飲<br>    func drinkingContainerViewsChange() {<br>        //先將Container View全部設為隱藏<br>        drinkingContainerViews.forEach {<br>            $0.isHidden = true //$0代表傳入的Container View<br>        }<br>        //將選取到的Container View設定為顯示<br>        drinkingContainerViews[segmentedControl.selectedSegmentIndex].isHidden = false<br>    }</pre><p>5. 將2個Container View原有的View Controller刪除並與2個Table View Controller用Embed的方式連接，在Table View Controller自訂想要的Cell樣式後，新增2個Table View Controller型別檔(及2個Table View Cell型別檔，並指定給Table View Controller及Cell</p><p>6. 解析Airtable API的JSON檔</p><pre><br>struct MenuList: Codable {<br>    var records: [DrinkingRecords]<br>}<br><br>struct DrinkingRecords: Codable {<br>    var fields: DrinkingDetail<br>}<br><br>struct DrinkingDetail: Codable {<br>    var price: Int<br>    var name: String<br>    var image: [imageDeatil]<br>    var iceHotKind: [String]<br>    var category: String<br>    <br>    struct imageDeatil: Codable {<br>        var url: URL<br>    }<br>}</pre><p>7. 透過API連線到Airtable取得飲品menu list，API_KEY置換成自己的</p><pre>let urlString = &quot;https://api.airtable.com/v0/appHy2q9FOUrGGhqS/DrinkingMenuList?api_key=API_KEY&quot;<br>        if let url = URL(string: urlString) {<br>            URLSession.shared.dataTask(with: url) { data, response, error in<br>                if let data {<br>                    let decoder = JSONDecoder()<br>                    do {<br>                        let menuDataList = try decoder.decode(MenuList.self, from: data)<br>                        for i in 0...(menuDataList.records.count - 1){<br>                            if menuDataList.records[i].fields.iceHotKind[0] == &quot;Ice&quot; {<br>                                self.menuList.append(menuDataList.records[i].fields)<br>                            }<br>                        }<br>                        DispatchQueue.main.async {<br>                            self.tableView.reloadData()<br>                        }<br>                    } catch {<br>                        print(error)<br>                    }<br>                }<br>            }.resume()<br>        }</pre><p>8. 取得資料後呈現在APP上的樣子</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*HXQToMlSwUgEk49_3SvW2A.png" /></figure><p>9. 最後完成banner輪播，需在Assets放置7張一樣大小的圖片(想輪播幾張就放幾張)，接下來撰寫程式碼(做法參考：<a href="https://youtu.be/rXkemZojlW8">https://youtu.be/rXkemZojlW8</a>)</p><p><strong><em>重點!!! Collection View的Estimate Size設成none及Image View的Content Mode設成Scale To Fill</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*yH4l90y5VNxVG1qpiT8qFA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*z2vOHL8IaPR310EOBiMu0w.png" /></figure><p>節錄程式碼如下：</p><pre>    //Controller conform to protocol<br>    class MainViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout<br>    <br>    //控制條件的計數<br>    var imageIndex: Int = 0<br>    <br>    //在Assets存了七張圖片，儲存圖片的陣列，因為要看起來一直往左滑動，故在最後補上第一張，才像是無限輪播<br>    let imageArray = [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;, &quot;1&quot;]<br><br>    //設定代理<br>    photoCarouselCollectionView.delegate = self<br>    photoCarouselCollectionView.dataSource = self<br>    <br>    //使用內建時間計數器每2秒換圖<br>    Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(autoPhotoCarousel), userInfo: nil, repeats: true)<br><br>    //執行自動輪播<br>    @objc func autoPhotoCarousel() {<br>        var indexPath: IndexPath<br>        imageIndex += 1<br>        if imageIndex &lt; imageArray.count {<br>            indexPath = IndexPath(item: imageIndex, section: 0)<br>            photoCarouselCollectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredHorizontally)<br>        } else {<br>            //當圖片輪播到最後一張將imageIndex歸零，改以沒有動畫回到第一張<br>            imageIndex = 0<br>            indexPath = IndexPath(item: imageIndex, section: 0)<br>            photoCarouselCollectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredHorizontally)<br>            autoPhotoCarousel()<br>        }<br>    }<br><br>    //回傳1個section<br>    func numberOfSections(in collectionView: UICollectionView) -&gt; Int {<br>        return 1<br>    }<br>    <br>    //回傳陣列中的圖片數量<br>    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {<br>        return imageArray.count<br>    }<br>    <br>    //自定義重用cell<br>    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {<br>        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: &quot;\(PhotoCarouselCollectionViewCell.self)&quot;, for: indexPath) as! PhotoCarouselCollectionViewCell<br>        cell.photoCarouselImageView.image = UIImage(named: imageArray[indexPath.item])<br>        return cell<br>    }<br>    <br>    //取得collection view位置及大小資訊<br>    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {<br>        return collectionView.bounds.size<br>    }<br>    <br>    //Collection View為左右捲動，所以cell左右間距為0<br>    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -&gt; CGFloat {<br>        return 0<br>    }<br>    <br>    //Collection View為左右捲動，所以cell上下間距為0<br>    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -&gt; CGFloat {<br>        return 0<br>    }</pre><p>夜深了～今天就到這邊吧～下次來談談訂單上傳的部份，謝謝觀賞～</p><p>關聯文章：</p><p><a href="https://medium.com/@taiyujou133/4-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-1-11acd2e6e21">#4 用RESTful API來訂杯珍奶喝吧！Part-1-畫面及功能簡介 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/e465cd063b70">#5 用RESTful API來訂杯珍奶喝吧！Part-2-Web官網整合介紹 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/7-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-4-%E8%A8%82%E5%96%AE%E4%B8%8A%E5%82%B3%E5%8F%8A%E6%9F%A5%E8%A9%A2-47259a618472">#7 用RESTful API來訂杯珍奶喝吧！Part-4-訂單上傳及查詢 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/8-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-5-%E8%A8%82%E5%96%AE%E4%BF%AE%E6%94%B9%E5%8F%8A%E5%88%AA%E9%99%A4-47f81d3c0cee">#8 用RESTful API來訂杯珍奶喝吧！Part-5-訂單修改及刪除 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8bfbffb276e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/6-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-3-e8bfbffb276e">#6 用RESTful API來訂杯珍奶喝吧！Part-3-menu呈現及banner輪播</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[#5 用RESTful API來訂杯珍奶喝吧！Part-2-Web官網整合介紹]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/5-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-2-e465cd063b70?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e465cd063b70</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Wed, 16 Nov 2022 10:27:09 GMT</pubDate>
            <atom:updated>2022-11-21T04:25:37.350Z</atom:updated>
            <content:encoded><![CDATA[<p>上篇大致上介紹了APP的使用方法及功能，這篇來說說首頁的建置過程囉～</p><p>步驟：</p><ol><li>建立一個View Controller，點選此新增的View Controller後，點擊Editor Window右下方的Embed in鈕，選取Tab Bar Controller</li><li>點選新增View Controller下方的Tab Bar區域，接著到Inspector面板在item欄位中填上&quot;首頁&quot;，Image改成house圖示</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*LjFM6-rFU9v3eOYSGnB0KA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*NjOvcceOz4a-Cj6gVee1TA.png" /></figure><p>3. 新增indexViewController.swift型別，並設定給View Controller</p><p>4. 切換到indexViewController.swift，撰寫下方程式：</p><pre>      var webView: WKWebView!<br><br>      override func loadView() {<br>          // 配置 WKWebView<br>          let webConfiguration = WKWebViewConfiguration()<br>          webView = WKWebView(frame: .zero, configuration:  webConfiguration)<br>          // 將我們的 view 指定為 webView<br>          view = webView<br>      }<br>    <br>      override func viewDidLoad() {<br>          super.viewDidLoad()<br>          // 讀取來自 URL 的網頁<br>          let myURL = URL(string:&quot;https://www.chunshuitang.com.tw/&quot;)<br>          let myRequest = URLRequest(url: myURL!)<br>          webView.load(myRequest)<br>      }</pre><p>以上完成後即將春水堂的官方首頁整合到APP中囉～～</p><p>關聯文章：</p><p><a href="https://medium.com/@taiyujou133/4-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-1-11acd2e6e21">#4 用RESTful API來訂杯珍奶喝吧！Part-1-畫面及功能簡介 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/6-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-3-e8bfbffb276e">#6 用RESTful API來訂杯珍奶喝吧！Part-3-menu呈現及banner輪播 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/7-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-4-%E8%A8%82%E5%96%AE%E4%B8%8A%E5%82%B3%E5%8F%8A%E6%9F%A5%E8%A9%A2-47259a618472">#7 用RESTful API來訂杯珍奶喝吧！Part-4-訂單上傳及查詢 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/8-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-5-%E8%A8%82%E5%96%AE%E4%BF%AE%E6%94%B9%E5%8F%8A%E5%88%AA%E9%99%A4-47f81d3c0cee">#8 用RESTful API來訂杯珍奶喝吧！Part-5-訂單修改及刪除 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e465cd063b70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/5-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-2-e465cd063b70">#5 用RESTful API來訂杯珍奶喝吧！Part-2-Web官網整合介紹</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[#4 用RESTful API來訂杯珍奶喝吧！Part-1-畫面及功能簡介]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/4-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-1-11acd2e6e21?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/11acd2e6e21</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Wed, 16 Nov 2022 09:27:31 GMT</pubDate>
            <atom:updated>2022-11-21T04:27:21.997Z</atom:updated>
            <content:encoded><![CDATA[<p>這支APP花了一點時間撰寫，以春水堂的飲料菜單為主題，寫了一個可以實際用來訂飲料的工具，以下就來說說這個開發APP的故事，說完再來去買杯珍奶喝喝～～</p><p>這篇先粗略介紹一下APP的主要功能，細部建置的過程之後分篇說明囉～</p><p>主要功能：</p><ol><li>首頁透過WebKit Framework寫幾行程式，就可將春水堂的官方網站整合到APP中。</li><li>瀏覽飲料menu，並可進行預訂飲料、查詢訂單、修改訂單、刪除訂單。</li><li>透過手機定位查詢所在位置附近的春水堂分店位置，並在地圖中標示使用者所在位置與分店相對位置。</li></ol><p>首頁：</p><p>春水堂官網己建置完善的RWD，所以在整合到APP中的過程並不複雜，只需透過IOS提供的WebKit Framework即可經鬆顯示網頁的內容。</p><p>畫面如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*p5uUZTR6uwNS9--Qz2Heaw.gif" /></figure><p>訂飲料：</p><p>這部份是APP主要功能，也是最花時間刻的部份，大致的內容如下：</p><ol><li>在menu的表頭以Collection View實現輪播banner。</li><li>透過Segmented Control及Container View配合實現冷熱飲畫面切換。</li><li>在Airtable建置品項menu，透過RESTful API串接Airtable，解析JSON內容後，使用Table View Controller呈現飲料品項。</li><li>點擊飲料選單中任一飲品，進入訂購飲品頁面，透過Ggoogle Map API依據使用者所在位置，手機定位後搜尋附近1000公尺內春水堂分店，點擊店名輸入欄位後，螢幕下方顯示Picker View，可由此選擇訂購店家。</li><li>選取Segmented Control客製飲料冰塊、甜度。</li><li>點選杯數欄位鍵盤可使用小鍵盤輸入，或可透過Steper增加或減少杯數。</li><li>如有其他客製需求，可在備註下方的Text View輸入需求告知店家。</li><li>最後輸入訂購者姓名及手機號碼，按 &quot;訂購&quot; 時出現Alert Controller與使用者確認飲品數量及金額，使用者&quot;確認&quot;後透過RESTful API的 POST 上傳新增訂單。(訂購時檢核店名、姓名、手機欄位空白則會顯示Alert Controller提醒輸入資訊)</li></ol><p>畫面如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*N0m9_pw2WfWHMRivyqmtxg.gif" /></figure><p>訂單查詢、修改、刪除：</p><ol><li>點選飲品訂購頁面右上角 &quot;訂單&quot; 進入訂單列表畫面，首先顯示Alert Controller告知使用者可點選每筆訂單進入修改、刪除頁面。</li><li>按掉通知訊息後，可滑動頁面檢視訂單，點選欲進行修改、刪除訂單進入調整頁面。</li><li>調整頁面透過Segue將前頁-訂單列表中點選的訂單內容傳到修改、刪除頁面。</li><li>調整頁面中店名的部分仍是透過Google Map API依使用者訂位將附近分店列出，點選後可由下方Picker選單中選擇訂購取件分店。</li><li>修改訂購飲品的內容後，按下方 &quot;修改&quot; 按鈕，出現提示按鈕詢問&quot;是否修改?&quot;，按 &quot;確認&quot; 透過RESTful API的 PUT 方式修改Airtable訂單列表的Table中飲品的資訊。</li><li>如欲刪除訂單，可按下方的 &quot;刪除&quot; 鈕，顯示Alert Controller確認畫面，訊息提示&quot;請問是否刪除?&quot;，與使用者確認是否刪透該筆訂單，使用者確認後，透過 RESTful API的 DELETE 將Airtable上此筆訂單記錄刪除。</li></ol><p>畫面如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*xnZgly_4_83HubZfnas9gw.gif" /></figure><p>顯示使用者所在位置附近1000公尺內的分店：</p><ol><li>點選附近店家Tab Bar Item &quot;附近店家&quot;，進入分店列表頁面，一開始先跟使用者確認是否提供位置資訊，使用者同意後進行定位取得使用者當前位置。</li><li>取得使用者當前位置後，依目前所在位置列出1000公尺內的分店資訊，如果附近沒有分店，則顯示Alert Controller提示附近沒有分店。</li><li>點選列表中右上 &quot;詳細&quot; 進入顯示使用者所在位置及分店的相對位置地圖。</li></ol><p>畫面如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*zy2xG0L_nbXLUeJ-Ner_ng.gif" /></figure><p>APP概觀介紹到這邊，後面的篇章再來寫寫建置的細部說明，謝謝各位不吝寶貴的時間看到最後～</p><p>這邊附上整APP操作的GIF圖：(圖片太大壓縮後不會Repeat，請重新整理就能從頭播放)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*7dCLO1t1Ma5cdwjLOFC5SQ.gif" /></figure><p>關聯文章：</p><p><a href="https://medium.com/@taiyujou133/e465cd063b70">#5 用RESTful API來訂杯珍奶喝吧！Part-2 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/6-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-3-e8bfbffb276e">#6 用RESTful API來訂杯珍奶喝吧！Part-3 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/7-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-4-%E8%A8%82%E5%96%AE%E4%B8%8A%E5%82%B3%E5%8F%8A%E6%9F%A5%E8%A9%A2-47259a618472">#7 用RESTful API來訂杯珍奶喝吧！Part-4-訂單上傳及查詢 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><p><a href="https://medium.com/@taiyujou133/8-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-5-%E8%A8%82%E5%96%AE%E4%BF%AE%E6%94%B9%E5%8F%8A%E5%88%AA%E9%99%A4-47f81d3c0cee">#8 用RESTful API來訂杯珍奶喝吧！Part-5-訂單修改及刪除 — 重來 就從 APPLE APP 開始吧 — Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11acd2e6e21" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/4-%E7%94%A8restful-api%E4%BE%86%E8%A8%82%E6%9D%AF%E7%8F%8D%E5%A5%B6%E5%96%9D%E5%90%A7-part-1-11acd2e6e21">#4 用RESTful API來訂杯珍奶喝吧！Part-1-畫面及功能簡介</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[#3 製作可愛Aliens(三眼怪)卡片,用程式也行哦～]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/3%E8%A3%BD%E4%BD%9C%E5%8F%AF%E6%84%9Baliens-%E4%B8%89%E7%9C%BC%E6%80%AA-%E5%8D%A1%E7%89%87-%E7%94%A8%E7%A8%8B%E5%BC%8F%E4%B9%9F%E8%A1%8C%E5%93%A6-b6fb0e8def7e?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6fb0e8def7e</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Mon, 31 Oct 2022 08:20:28 GMT</pubDate>
            <atom:updated>2022-11-03T02:40:04.201Z</atom:updated>
            <content:encoded><![CDATA[<p>由於太太很喜歡三眼怪，再加上老是唸叨很久沒送卡片了，順便展現一下技術給她看～就用程式製作一張三眼怪小可愛卡片送她吧～</p><p>先來看一下成品圖：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hb4xV14vDMehnyAJDW-puw.png" /></figure><p>主要使用工具元件：<br>Playground、UIImage、UIImageView、UILabel</p><p>1.先將圖片加入Playground左側導覽列的Resources資料夾中(檔名：aliens.jpeg)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*vyijOkCJfteRKuuPhRPtUg.png" /></figure><p>2.使用UIImage元件產生圖片</p><pre>let image = UIImage(named: &quot;aliens.jpeg&quot;)</pre><p>3.產生圖片片畫面UIImageView</p><pre>let imageView = UIImageView(image: image)</pre><p>4.設定圖片的位置長寬、圖片呈現方式、透明度、4個角設為圓角</p><pre>//位置長寬<br>imageView.frame = CGRect(x: 0, y: 0, width: 1000, height: 1000)</pre><pre>//圖片呈現方式<br>imageView.contentMode = .scaleToFill<br> <br>//透明度<br>imageView.alpha = 0.7<br> <br>//4個角設為圓角<br>imageView.layer.cornerRadius = 70<br>imageView.clipsToBounds = true</pre><p>5.用UILabel在圖片上想要的位置顯示想表達的文字</p><pre>//文字-1<br>//顯示的位置及Label的大小<br>let messageLabel1 = UILabel(frame: CGRect(x: 250, y: 80, width: 500, height: 50))</pre><pre>//設定文字大小<br>messageLabel1.font = UIFont.systemFont(ofSize: 40)</pre><pre>//Label中加入想顯示的文字內容<br>messageLabel1.text = &quot;Meow 永遠快樂～&quot;</pre><pre>//使用addSubview method將Label加入畫面imageView.addSubview(messageLabel1)</pre><pre>//文字-2<br>let messageLabel2 = UILabel(frame: CGRect(x: 650, y: 560, width: 500, height: 100))<br>messageLabel2.font = UIFont.systemFont(ofSize: 23)</pre><pre>//將Label設定可以輸入多行<br>messageLabel2.numberOfLines = 0</pre><pre>messageLabel2.text = &quot;Oh~oh~ \n I love you forever~❤️&quot;<br>imageView.addSubview(messageLabel2)</pre><p>6.加入圖片周圍的爪子圖(檔名：claw.png)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*lWj6iLZgcm4vOlgZz3hhyQ.png" /></figure><p>7.將爪子圖片(claw.png)放入Label元件，設定位置及旋轉角度，並圍繞圖片四周</p><pre>//產生圖片<br>let meowClaw = UIImage(named: &quot;claw.png&quot;)</pre><pre>//宣告變數<br>var meowClawView = UIImageView()<br>var emojiLabel = UILabel()<br>var x = 0<br>var y = 0</pre><pre>//使用for loop將爪子圖圍繞在主圖的四周<br>//左右2邊<br>for _ in 1...10 {<br>    meowClawView = UIImageView(image: meowClaw)<br>    meowClawView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)<br>    emojiLabel = UILabel(frame: CGRect(x: 0, y: y, width: 100,  height: 100))<br>    emojiLabel.addSubview(meowClawView)<br>    <br>    //旋轉角度<br>    emojiLabel.transform = CGAffineTransform(rotationAngle: .pi / 180 * 45)<br>    imageView.addSubview(emojiLabel)<br>    <br>    y += 100<br>}</pre><pre>y = 0<br>for _ in 1...10 {<br>    meowClawView = UIImageView(image: meowClaw)<br>    meowClawView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)<br>    emojiLabel = UILabel(frame: CGRect(x: 900, y: y, width: 100, height: 100))<br>    emojiLabel.addSubview(meowClawView)<br>    emojiLabel.transform = CGAffineTransform(rotationAngle: .pi / 180 * (-45))<br>    imageView.addSubview(emojiLabel)<br>    <br>    y += 100<br>}</pre><pre>//上下2邊<br>for _ in 1...8 {<br>    meowClawView = UIImageView(image: meowClaw)<br>    meowClawView.frame = CGRect(x: 100, y: 0, width: 100, height: 100)<br>    emojiLabel = UILabel(frame: CGRect(x: x, y: 0, width: 100, height: 100))<br>    emojiLabel.addSubview(meowClawView)<br>//    emojiLabel.transform = CGAffineTransform(rotationAngle: .pi / 180 * 45)<br>    imageView.addSubview(emojiLabel)<br>    <br>    x += 100<br>}</pre><pre>x = 0<br>for _ in 1...8 {<br>    meowClawView = UIImageView(image: meowClaw)<br>    meowClawView.frame = CGRect(x: 100, y: 0, width: 100, height: 100)<br>    emojiLabel = UILabel(frame: CGRect(x: x, y: 900, width: 100, height: 100))<br>    emojiLabel.addSubview(meowClawView)<br>//    emojiLabel.transform = CGAffineTransform(rotationAngle: .pi / 180 * (-45))<br>    imageView.addSubview(emojiLabel)<br>    <br>    x += 100<br>}</pre><pre>//在Playground顯示做好的卡片<br>imageView</pre><p>完整程式碼：</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07f5a97feaa72307b01eb7e40420598f/href">https://medium.com/media/07f5a97feaa72307b01eb7e40420598f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6fb0e8def7e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/3%E8%A3%BD%E4%BD%9C%E5%8F%AF%E6%84%9Baliens-%E4%B8%89%E7%9C%BC%E6%80%AA-%E5%8D%A1%E7%89%87-%E7%94%A8%E7%A8%8B%E5%BC%8F%E4%B9%9F%E8%A1%8C%E5%93%A6-b6fb0e8def7e">#3 製作可愛Aliens(三眼怪)卡片,用程式也行哦～</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[#2 來去空桑Play-食物語電子書]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/2%E4%BD%9C%E6%A5%AD-%E4%BE%86%E5%8E%BB%E7%A9%BA%E6%A1%91play-%E9%A3%9F%E7%89%A9%E8%AA%9E%E9%9B%BB%E5%AD%90%E6%9B%B8-9ce6fd54fce7?source=rss-3d26c15dc7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ce6fd54fce7</guid>
            <dc:creator><![CDATA[Tai]]></dc:creator>
            <pubDate>Sun, 30 Oct 2022 05:07:27 GMT</pubDate>
            <atom:updated>2022-11-03T02:40:24.389Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DsSGExFR5Im_fy4opjFlzQ.png" /><figcaption>食物語電子書Storyboard結構圖</figcaption></figure><p>一個持續玩了快3年的遊戲，用IOS APP做一個電子書紀念一下囉～</p><p>使用Storyboard及UIKit幾個基本的元件完成APP — 食物語電子書。</p><p>使用到的元件：</p><p>Tab Bar Controller、Navigation Controller、Table View Controller、View Controller、Container View、Scroll View、Image View、Text View、Label、Segue</p><p>1.製作食物語遊戲”介紹”畫面：</p><p>(1) 點選成立專案時就己產生的View Controller</p><p>(2) 點擊Editor Window右下方的Embed in鈕，在選單中選擇Tab Bar Controller</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/56/1*zifTU2Pw4C0zw4BCUlzMNw.png" /></figure><p>(3) 在Inspector修改View Controller上Bar Item中的Title=介紹、Image=book.fill</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*3lKvrW0OncS9Qm-YJlJGIA.png" /></figure><p>(4) 將Container View及Image View新增到View Controller(注意:Container View要在Image View的上方，以免被Image View遮到內容)，2個元件大小拉成View Controller大小一致，並刪除Container View預設產生的View Controller，Image View=Background-1.png</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*ufFyWAxCnl2t-fMAoCgIKA.png" /></figure><p>(5) 新增空白View Controller至Editor Window，於新增的View Controller中增加各1個Image View及Text View，調整成想要的大小後，設定Image=介紹header.png、TextView貼上介紹文內容</p><p>(6) 從Container View拉線(Segue)至新增的View Controller，在選單中選擇Embed，之後將View Controller、Text View的Background=Clear Color這樣才能看到背景圖</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*UZ5mMYFzPRtaA2x8nXZzmA.png" /></figure><p>2.製作”食魂”畫面：</p><p>(1) 複製”介紹”畫面Image View=Background-1.png，改成Image View=Background-2.png，點擊修改後的View Controller，點Editor Window右下的Embed in鈕，選擇Navigation Controller<strong><em>(提示：如果誤刪Navigation Controller至連線目的View Controller的Segue，可由Navigation Controller再拉一次，選單中選root view controller即可)</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*FvdGZoCIQwmXZ8xvQ1dVbw.png" /></figure><p>(2) 從Tab Bar Controller拉線(Segue)至上個步驟新增的Navigation Controller，在選單選擇view controllers，接著修改Navigation Controller下方的Bar Item中的Title=食魂、Image=person</p><p>(3) 新增Table View Controller，從Image View=Background-2.png的Container View拉線(Segue)到Table View Controller，選單選擇Embed，修改Inspector Table View的content=Static Cells，刪除Structure的Table View下方2個Cell，待第一個Cell設定好之後用複製的比較快</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*Kbo0Oa2iT6utkkWrSKgHuw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*I270pUcY5Z5su7mxtlVAiA.png" /></figure><p>(4) Table View改成Static Cell後，Table View會產生預設的Header及Footer要將Inspector中Section下Header及Footer的Estimate=0，才不會畫面上下都出現灰色條塊遮住畫面</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*_7rwUxYMHQOhfMG77GjJqQ.png" /></figure><p>(5) 新增View至Structure Window中Table View Controller的Table View與Table View Section中間當成header，並在header中新增Scroll View，讓圖片可以左右移動檢視(細節：參考”<a href="https://www.google.com/search?q=%E9%A3%9F%E9%AD%82%E8%8B%B1%E6%96%87&amp;newwindow=1&amp;sxsrf=ALiCzsYu6xdkT_pRdzhhl4yonV3Yewtt2w%3A1667028261070&amp;ei=JdVcY6P0A5GkoATmgaygCQ&amp;ved=0ahUKEwjjmtOa9IT7AhUREogKHeYAC5QQ4dUDCA8&amp;uact=5&amp;oq=%E9%A3%9F%E9%AD%82%E8%8B%B1%E6%96%87&amp;gs_lp=Egxnd3Mtd2l6LXNlcnC4AQP4AQEyBRAAGKIEMgcQABgeGKIEMgUQABiiBMICBBAjGCfCAgUQABiABMICCBAAGIAEGLEDwgILEAAYgAQYsQMYgwHCAgoQABiABBixAxgKwgIEEAAYQ8ICBxAAGLEDGEPCAggQLhiABBixA8ICBBAAGB7CAgYQABgeGArCAgoQABixAxiDARhDwgIOEC4YgAQYsQMYxwEYrwHCAgcQIxjqAhgnwgILEC4YgAQYsQMYgwHCAgYQABgeGA_CAggQABixAxiDAcICERAuGIAEGLEDGIMBGMcBGK8BwgILEC4YgAQYxwEYrwHCAgUQLhiABKgCCki0NFAAWPYxcAJ4AcgBAJABAJgBc6ABtQ6qAQQyMy4z4gMEIEEYAOIDBCBGGACIBgE&amp;sclient=gws-wiz-serp"><em>設定 content size，實現水平捲動，上下捲動和分頁的 scroll view</em></a>”)，新增Button覆蓋在Image View之上，再拉線(Segue)到Detail View Controller即可實現點選Scroll View圖片轉到食魂簡介紹畫面</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*rzojZ-E8YBVoGU58QZjTng.png" /></figure><p>(6) Cell中新增各1個Image View及Label，調整好要的樣式後複製需求的數量，並設定Image View及Label</p><p>(7) 新View Controller製作點選Cell出現的內容畫面，在View Controller上新增Image View、Label、Text View各一個調整成想要的樣式後，複製跟Cell一樣的數量</p><p>(8) 從Cell依序拉線(Segue)到對應的View Controller</p><p>(9) 新增一個空白的View到Table View Controller上方的Item Bar，在Table View Controller上方會出現空白的View，將View的Background=Clear Color，然後將Table View Cell拉線到這個View，選單點選selectedBackgroundView，則點Cell就不會有顏色出現(參考：<a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E8%A8%AD%E5%AE%9A%E8%A1%A8%E6%A0%BC-cell-%E9%BB%9E%E9%81%B8%E6%99%82%E7%9A%84%E8%83%8C%E6%99%AF%E9%A1%8F%E8%89%B2-b59d0abe4b9d"><em>設定表格 cell 點選時的背景顏色</em></a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*-CEe5M9djpal2eim4FiUpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*x_dX6FptoMsjEVM5MzxUVA.png" /></figure><p>成品GIF：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*u3gjWRtk0CVS1ZXZ25tMeQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ce6fd54fce7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/2%E4%BD%9C%E6%A5%AD-%E4%BE%86%E5%8E%BB%E7%A9%BA%E6%A1%91play-%E9%A3%9F%E7%89%A9%E8%AA%9E%E9%9B%BB%E5%AD%90%E6%9B%B8-9ce6fd54fce7">#2 來去空桑Play-食物語電子書</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>