<?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 Nutdanai Vankrua on Medium]]></title>
        <description><![CDATA[Stories by Nutdanai Vankrua on Medium]]></description>
        <link>https://medium.com/@nutdanai.vankrua?source=rss-1dfd46d31bbf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kvbv8TSbuHdygdfsbf9ryw@2x.jpeg</url>
            <title>Stories by Nutdanai Vankrua on Medium</title>
            <link>https://medium.com/@nutdanai.vankrua?source=rss-1dfd46d31bbf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 19:51:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nutdanai.vankrua/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[Kafka Idempotent Producer คืออะไร]]></title>
            <link>https://medium.com/@nutdanai.vankrua/kafka-idempotent-producer-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-72c959a1483b?source=rss-1dfd46d31bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/72c959a1483b</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Nutdanai Vankrua]]></dc:creator>
            <pubDate>Sat, 01 Aug 2026 16:03:21 GMT</pubDate>
            <atom:updated>2026-08-01T16:03:21.048Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9eR4LFPysM5lGMqbtgGEuw.png" /></figure><blockquote>การทำอะไรบางอย่างซ้ำๆ แต่ได้ผลลัพธ์เหมือนทำครั้งเดียว</blockquote><p>ถ้าเอามาอธิบายในโลกของ Kafka ง่าย ๆ คือ <strong>Kafka idempotent producer</strong> ช่วยให้ producer ส่งข้อความซ้ำได้อย่างปลอดภัยเวลามีปัญหาชั่วคราว เช่น network สะดุด, broker ตอบช้า, หรือ ack หายไป</p><p>ผลลัพธ์คือ Kafka จะไม่บันทึก record เดิมซ้ำโดยไม่จำเป็น</p><p>ความสามารถนี้เพิ่มเข้ามาใน <strong>Kafka 0.11</strong> เพื่อแก้ปัญหาเรื่อง message ซ้ำจากการ retry</p><h3>ทำไมเรื่องนี้ถึงสำคัญ</h3><p>สมมติว่า producer ส่งข้อความไปที่ Kafka แล้วเกิดเหตุการณ์นี้:</p><ul><li>ส่งสำเร็จไปแล้ว แต่ ack จาก broker หาย</li><li>producer คิดว่ายังไม่สำเร็จ เลย retry</li><li>ถ้า Kafka ไม่รู้ว่าข้อความนี้เคยถูกเขียนไปแล้ว มันอาจบันทึกซ้ำ</li></ul><p>ปัญหานี้ดูเล็ก แต่ในระบบจริงมันสร้างผลกระทบได้มาก โดยเฉพาะงานที่ต้องการความถูกต้อง เช่น</p><ul><li>ธุรกรรมการเงิน</li><li>การสั่งซื้อสินค้า</li><li>ขั้นตอน workflow ที่ต้องเรียงลำดับให้ถูก</li></ul><p>ถ้าเหตุการณ์ถูกส่งซ้ำหรือเรียงผิดลำดับ ระบบ downstream จะตีความผิดได้ทันที</p><h3><strong>Kafka idempotent producer ช่วยอะไรบ้าง</strong></h3><p>เมื่อเปิดใช้งาน idempotent producer:</p><ul><li>producer สามารถ retry ได้อย่างปลอดภัยมากขึ้น</li><li>Kafka ช่วยตรวจจับ duplicate record ที่เกิดจาก retry</li><li>ลดโอกาสเกิดข้อความซ้ำเพราะปัญหาชั่วคราว</li><li>ช่วยให้การส่งข้อมูลมีความน่าเชื่อถือมากขึ้น</li></ul><p>แต่ต้องเข้าใจให้ชัดว่า:</p><blockquote><strong>idempotent producer ไม่ได้ป้องกัน duplicate ทุกกรณี</strong></blockquote><p>มันป้องกัน duplicate ที่เกิดจาก <strong>producer retry</strong> เป็นอย่างเดียว</p><p>ถ้าระบบของคุณตั้งใจส่ง event เดิมซ้ำหรือ producer restart แล้วเริ่ม session ใหม่ หรือมี producer หลายตัวส่ง event เดียวกัน ต้องแก้ด้วยวิธีอื่น เช่น application-level deduplication หรือ Kafka transactions</p><h3><strong>ตั้งค่า producer ยังไงให้เหมาะกับ idempotency</strong></h3><p>ถ้าใช้ Sarama ใน Go การตั้งค่าพื้นฐานที่ควรมีคือ:</p><ul><li>⁠config.Producer.Idempotent = true</li><li>⁠config.Producer.RequiredAcks = sarama.WaitForAll</li><li>⁠config.Producer.Retry.Max &gt; 0</li><li>⁠config.Net.MaxOpenRequests = 1</li></ul><p><strong>แต่ละค่าหมายถึงอะไร</strong></p><p>Idempotent = true</p><ul><li>เปิดใช้ producer แบบ idempotent</li></ul><p>⁠RequiredAcks = WaitForAll</p><ul><li>รอให้ replica ที่อยู่ใน ISR ตอบรับก่อนถึงจะถือว่าสำเร็จ</li></ul><p>Retry.Max &gt; 0</p><ul><li>ถ้าเจอ error ชั่วคราว จะ retry ได้</li></ul><p>⁠MaxOpenRequests = 1</p><ul><li>จำกัดจำนวน request ที่ยังไม่ ack บน connection เดียว</li><li>ช่วยรักษาลำดับและลดความเสี่ยงเรื่อง ordering ตอน retry</li></ul><p>โดยทั่วไป Kafka จะตั้งค่า ⁠max.in.flight.requests.per.connection ไว้ที่ 5 เป็นค่าเริ่มต้น</p><p>แต่ถ้าอยากเข้มงวดกับ order ของ message การตั้งค่าเป็น ⁠1 เป็นทางเลือกที่ปลอดภัยสสุด แม้ throughput จะลดลง</p><h3>ตัวอย่าง Code Go</h3><pre>package main<br><br>import (<br>    &quot;fmt&quot;<br>    &quot;log&quot;<br><br>    &quot;github.com/Shopify/sarama&quot;<br>)<br><br>func main() {<br>    brokers := []string{&quot;localhost:9092&quot;}<br>    topic := &quot;my-topic&quot;<br><br>    config := sarama.NewConfig()<br><br>    // ต้องเป็นเวอร์ชัน Kafka ที่รองรับ idempotent producer<br>    config.Version = sarama.V2_0_0_0<br><br>    // Idempotent producer settings<br>    config.Producer.Idempotent = true<br>    config.Producer.RequiredAcks = sarama.WaitForAll<br>    config.Producer.Retry.Max = 5<br>    config.Net.MaxOpenRequests = 1<br><br>    // แนะนำให้เปิด<br>    config.Producer.Return.Successes = true<br><br>    producer, err := sarama.NewSyncProducer(brokers, config)<br>    if err != nil {<br>        log.Fatalf(&quot;failed to create producer: %v&quot;, err)<br>    }<br>    defer func() {<br>        if err := producer.Close(); err != nil {<br>            log.Printf(&quot;failed to close producer: %v&quot;, err)<br>        }<br>    }()<br><br>    msg := &amp;sarama.ProducerMessage{<br>        Topic: topic,<br>        Key:   sarama.StringEncoder(&quot;user-1&quot;),<br>        Value: sarama.StringEncoder(&quot;hello from idempotent producer&quot;),<br>    }<br><br>    partition, offset, err := producer.SendMessage(msg)<br>    if err != nil {<br>        log.Fatalf(&quot;failed to send message: %v&quot;, err)<br>    }<br><br>    fmt.Printf(&quot;message sent to partition %d at offset %d\n&quot;, partition, offset)<br>}</pre><h3><strong>acks คืออะไร และทำไมถึงมีผล</strong></h3><p>เวลา producer ส่ง message ไป Kafka มันสามารถเลือกได้ว่าจะรอ acknowledgment ระดับไหนก่อนถือว่าสำเร็จ</p><p>acks=0</p><ul><li>ส่งแล้วไม่รอคำตอบ</li><li>เร็วที่สุด</li><li>เสี่ยงข้อมูลหายสูงที่สุด</li></ul><p>เหมาะกับข้อมูลที่หายได้บ้าง เช่น</p><ul><li>metrics</li><li>logs</li><li>telemetry</li><li>clickstream ที่ยอมให้ข้อมูลบางส่วนหายได้</li></ul><p>⁠acks=1</p><ul><li>leader ตอบกลับหลังเขียนลง local log</li><li>แต่ถ้า leader พังก่อน replicate ไป follower ข้อมูลอาจหายได้</li></ul><p>เหมาะกับงานที่ต้องการความเร็วสูงและยอมรับ loss เล็กน้อยได้</p><p>⁠acks=all</p><ul><li>leader จะรอให้ in-sync replicas ตอบรับ</li><li>ปลอดภัยที่สุด</li><li>ช้ากว่าเพราะต้องรอ replication</li></ul><p>เหมาะกับข้อมูลสำคัญทางธุรกิจ เช่น</p><ul><li>คำสั่งซื้อ</li><li>ธุรกรรมการเงิน</li><li>event ที่ห้ามหาย</li></ul><h3><strong>min.insync.replicas คืออะไร</strong></h3><p>คือจำนวน replica ขั้นต่ำที่ต้องอยู่ในสถานะ sync เพื่อให้ Kafka ยอมรับ write เมื่อใช้ ⁠acks=all</p><p>ถ้าจำนวน ISR ต่ำกว่าค่านี้ Kafka จะ <strong>reject writes</strong> แทนที่จะรับข้อมูลแบบไม่ปลอดภัย</p><p>พูดง่าย ๆ คือมันเป็น safety gate</p><p>ช่วยไม่ให้ producer เข้าใจผิดว่าข้อมูลถูกเขียนอย่างปลอดภัย ทั้งที่ replication ยังไม่แข็งแรงพอ</p><p><strong>ตัวอย่างค่าที่นิยมใน production</strong></p><ul><li>⁠replication.factor=3</li><li>⁠min.insync.replicas=2</li><li>⁠acks=all</li></ul><p>concept คร่าวๆ ประมาณนี้ หวังว่าบทความนี้จะทำให้เข้าใจกลไกการทำงานของ Kafka มากขึ้น จนกว่าจะพบกันใหม่ สวัสดีครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72c959a1483b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git เริ่มต้น Project ใหม่]]></title>
            <link>https://medium.com/@nutdanai.vankrua/git-%E0%B9%80%E0%B8%A3%E0%B8%B4%E0%B9%88%E0%B8%A1%E0%B8%95%E0%B9%89%E0%B8%99-project-%E0%B9%83%E0%B8%AB%E0%B8%A1%E0%B9%88-b968939c6f61?source=rss-1dfd46d31bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/b968939c6f61</guid>
            <dc:creator><![CDATA[Nutdanai Vankrua]]></dc:creator>
            <pubDate>Sun, 01 Jun 2025 14:28:37 GMT</pubDate>
            <atom:updated>2025-06-01T14:28:37.856Z</atom:updated>
            <content:encoded><![CDATA[<p>เรารู้แล้วว่าคำสั่งที่ต้องใช้ในแต่ล่ะวันมีอะไรจากบทความนี้</p><p><a href="https://medium.com/@nutdanai.vankrua/git-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B9%83%E0%B8%99%E0%B8%8A%E0%B8%B5%E0%B8%A7%E0%B8%B4%E0%B8%95%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%88%E0%B8%B3%E0%B8%A7%E0%B8%B1%E0%B8%99-9234c0dc66a2">Git คืออะไร ในชีวิตประจำวัน</a></p><p>แต่ถ้าเราเริ่มต้น Project เองล่ะ จะต้องรู้คำสั่งอะไรบ้าง?</p><ul><li>Git init: เริ่มต้นให้ navigate ไป folder ที่เป็น project ของเราก่อน</li></ul><pre>// ตัวอย่างการ navigate ใน terminal<br>cd ~/Documents/work/my-project<br><br>// เพื่อ check ว่าตัวเองอยู่ที่ไหนลองคำสั่งนี้<br>pwd<br><br>// เอา git มาใส่ใน project<br>git init</pre><ul><li>Git status : ใช้ดูว่าตอนนี้ git setup สำเร็จแล้วหรือไม่</li></ul><pre>git status<br><br>// ตัวอย่าง output<br>On branch main<br>Your branch is up to date with &#39;origin/main&#39;.<br><br>nothing to commit, working tree clean</pre><p>ทั้งหมดนี้เรายังทำงานอยู่คนเดียวบนเครื่องตัวเอง ถ้าเราอยากทำงานร่วมกับคนอื่นเราต้องเอา code เราไปไว้บน server หรือหมายถึงเครื่องที่อยู่บน internet</p><p>ที่ๆ คนอื่นสามาถเข้าถึงได้เหมือนกัน เราจะเรียกเครื่องๆ นี้ว่า `remote server`</p><p>เราอาจได้ยินผ่านหูมาบ้างกับคำเล่านี้ Github, BitBucket, Gitlab องค์กรเหล่านี้มีเครื่องคอมตั้งไว้บน internet แล้วเราสามารถ push code ขึ้นไปที่นั้นได้ เรายังสามารถกำหนดได้ว่า code เราสามารถเข้าถึงได้ทุกคน (public) หรือได้เฉพาะบางคน (private)</p><p>ในแต่ล่ะองค์กรที่มีบริการเหล่านี้ให้ เราสามารถกดสร้างขึ้นมาแล้วจะมีให้กดปุ่ม clone หรือดูได้ว่า endpoint ของ project นี้อยู่ที่ไหน (ศัพท์ที่ใช้กันส่วนใหญ่คือ repository ซึ่งเป็นที่ๆ เก็บ code project ของเรา)</p><p>เราจะเอา endpoint นั้นมาตั้งค่าใน project ของเรา เพื่อที่เรา save หรือ commit code เสร็จ เราก็จะเอา code ขึ้นไปที่ remote เพื่อให้คนอื่นได้ code ของเราไปด้วย</p><ul><li>Git remote : ใช้การตั้งค่า remote server ที่จะเอา code ขึ้นไปเก็บ</li></ul><pre>// คำสั่งที่ใช้ตั้งค่า remote ให้กับ folder ที่ git init ไป<br>git remote add origin https://github.com/username/my-project.git<br><br>// คำสั่งที่ใช้ดูว่าเราตั้งค่า remote ต่างๆ ถูกหรือเปล่า<br>git remote -v<br></pre><p>แค่นี้ก็เป็นอันเสร็จการตั้งค่า project เพื่อทำงานกับคนอื่นแล้ว หลังจากนั้นก็เป็นคำส่งเพื่อเอา code ขึ้น (push) ไปที่ remote หรือดึง (pull) code ลงมาที่เครื่องตัวเอง</p><ul><li>Git push : หลังจากที่ commit code ต่างๆ เสร็จก็จะเอา code commit 1, 2, 3, … ที่ยังไม่มีที่ remote ขึ้น</li></ul><pre>// -u เพื่อบอกให้ git คอยฟังว่า branch ที่ชื่อ master บน remote มีการขยับหรือเปล่า<br>// origin คือชื่อ remote ที่เรากำหนดตอนใช้คำสั่ง remote add<br>// master คือชื่อ branch ที่เราทำงานอยู่ (อาจไม่ใช่ master ให้ดูดีๆ ว่าตอนสร้าง repo ค่าเริ่มต้นคืออะไร)<br>git push -u origin master</pre><ul><li>Git pull : ดึง code ใหม่ๆ ที่อยู่บน remote ลงมาที่เครื่องของเรา</li></ul><pre>// ไม่ต้องกำหนดชื่อ branch โดยปกติเราจะดึง code ลงมา ณ branch ที่ตัวเองอยู่ อยู่แล้ว<br>git pull</pre><ul><li>Git fetch : ไป check ว่า code บน remote ไม่การขยับหรือเปล่า แต่ยังไม่ดึงลงมาที่เครื่องของตัวเอง</li></ul><pre>git fetch</pre><p>ถึงตรงนี้จะได้ยินศัพท์ใหม่เพิ่มขึ้นมาคือ branch ซึ่งเดี๋ยวจะอธิบายเพิ่มเติมในบทความถัดไป จนถึงตอนนั้นอย่าลืมกดติดตามนะครับ ขอบคุณครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b968939c6f61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git คืออะไร ในชีวิตประจำวัน]]></title>
            <link>https://medium.com/@nutdanai.vankrua/git-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B9%83%E0%B8%99%E0%B8%8A%E0%B8%B5%E0%B8%A7%E0%B8%B4%E0%B8%95%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%88%E0%B8%B3%E0%B8%A7%E0%B8%B1%E0%B8%99-9234c0dc66a2?source=rss-1dfd46d31bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/9234c0dc66a2</guid>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Nutdanai Vankrua]]></dc:creator>
            <pubDate>Mon, 12 May 2025 10:11:32 GMT</pubDate>
            <atom:updated>2025-06-01T14:29:59.861Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Gs__K6t45LxUd4q5NcqFg.png" /></figure><p>คำตอบสั้นๆ มันคือ Version Control</p><blockquote>Version Control คืออะไร?</blockquote><p>ถ้าเกิดไม่มี Git (กิท) ในสายงานอื่นเราอาจคุ้นเคยกับรูปแบบเหล่านี้</p><ul><li>รายงานเล่มจบปริญญาตรี version 1, 2, 2.1, 2.2, final 2.1, final 2.4 (ไม่ใช้แล้วกลับไป 2.1 นะ), ฯลฯ</li><li>design version 1, 2, 3, 3.1, 4, 4.1, final, final 1.0 ฯลฯ</li></ul><p>ทิ้งไว้ใน folder เดียวกัน อยู่งานอื่น แทรกต้องไปสลับสมาธิไปทำงานกลับมาจำไม่ได้แล้วว่าใช้ file ไหนเพื่อทำงานต่อ สังเกตดีๆ เราก็ทำการควบคุม version ของงานกันอยู่ทุกวันแล้ว แต่ทำด้วยมือและความจำ แล้วถ้าเป็น code ที่มีคน 10 คนเขียนด้วยกันทุกวันหลายแสนบรรทัด งานไม่เดินและต่อให้งานเดินก็หนักสมองแน่นอน</p><blockquote>คำสั่งในการใช้ Git ประจำวันที่ต้องรู้</blockquote><ul><li>Git Add: เป็นสิ่งแรงตอนจะ save งาน หรือฉันพร้อมจะบันทึกงาน ณ เวลานี้ไว้ เราก็จะ add file นั้นลงในกล่องๆ หนึ่งเรียกว่า Stage เพื่อเตรียม Commit (บันทึก)</li></ul><pre>// add ทีล่ะ file<br>git add ./core/market.go<br><br>// add file ทั้งหมดที่อยู่ใน folder<br>git add ./core</pre><ul><li>Git Remove เพลอ add ผิด file ลงไปใน stage ก็ remove (เอาออก)ได้</li></ul><pre>// remove ทีล่ะ file<br>git remove ./core/market.go<br><br>// remove file ทั้งหมดที่อยู่ใน folder<br>git remove ./core</pre><ul><li>Git Commit บันทึกงานที่อยู่ stage ทั้งหมดและเกิด commit sha ขึ้นมา ให้มองเป็นเลข version ที่ใช้อ้างอิง ณ เวลานั้นๆ</li><li>Git log ไว้ดูประวัติย้อนหลังของสิ่งที่ commit ไป</li></ul><pre>// ตัวอย่างคำส่ัง<br>git log<br><br>// หรือถ้าจะดูเป็นเส้น graph<br>git log --graph<br><br>// ตัวอย่าง Output ที่เห็น<br>commit 0fd55d7f649bd709d42d0733c0a76f8fcdb74802<br>Merge: 10ca7f66143 0bcbde4940e<br>Author: Pavel Yaskevich &lt;pyaskevich@apple.com&gt;<br>Date:   Fri May 9 21:04:08 2025 -0700<br><br>    Merge pull request #81413 from xedin/rename-notes-file-for-noinisolated-nonsending-feature<br><br>    [Diagnostics] Rename the note file to match the `NonisolatedNonsendin…<br><br>commit 10ca7f66143e7eb865d8d26413385e09c01c0cb3<br>Merge: c16e93f2cde 70b413dc56f<br>Author: Slava Pestov &lt;spestov@apple.com&gt;<br>Date:   Fri May 9 22:28:31 2025 -0400<br><br>    Merge pull request #81299 from slavapestov/remote-mirrors-meet-packs<br><br>    RemoteInspection: Support for parameter packs<br><br>commit c16e93f2cdeb532fc38713825956d0da6650c5d4<br>Merge: ff5b82170c8 9d493db4790<br>Author: Doug Gregor &lt;dgregor@apple.com&gt;<br>Date:   Fri May 9 19:12:58 2025 -0700<br><br>    Merge pull request #81420 from DougGregor/se-0470-synthesized-conformances-main-actor<br><br>    [SE-0470] Fix synthesized conformances with default main actor isolation<br><br>commit ff5b82170c88956c5a67a27beb05f8e8d622da7b<br>Merge: 49aea31e411 61ac302fb7e<br>Author: Doug Gregor &lt;dgregor@apple.com&gt;<br>Date:   Fri May 9 19:00:54 2025 -0700<br><br>    Merge pull request #81419 from DougGregor/lookupexpr-effects-cleanup<br><br>    [Effects] Simplify handling of LookupExpr in effects checking</pre><blockquote>BONUS POINTS!!!</blockquote><p>Commit เป็นสิ่งที่สำคัญมากๆ แต่หลายคนกลับใช้งานไม่เต็มความสามารถของมันเช่น</p><pre>git commit -m &quot;add log&quot; // log อะไร เพิ่มทำไม เกี่ยวกับงานอะไร<br>git commit -m &quot;fix bug&quot; // bug อะไร bug จริงหรือเปล่า หรือเป็นงานที่ตั้งใจออกแบบนั้น แต่คนเรียกใช้งานผิดหรือเปล่า<br>git commit -m &quot;add feature&quot; // feature อะไร มันคืองานชิ้นไหน</pre><p>นอกจากแต่ล่ะ commit พอมานั่งดูย้อนหลังแล้ว ไม่รู้เลยว่าเกี่ยวกับอะไร ยังต้องกดเข้าไปดู commit นั้นๆ ว่าแก้อะไรไปบ้างและพยายามจับเชื่อมโยงว่ามันเกี่ยวกับอะไร ถ้าเป็นแบบนี้ก็เริ่มไม่ต่างจากทำ version control เองกับมือ</p><p>จำไว้ในสายงานนี้ <strong><em>เขียน code 10% อ่าน &amp; วางแผนแก้ปัญหา 90%</em></strong></p><p>อย่าลืมตบมือและ subscribe บนความถัดไปที่จะอยู่ใน series ของ Git ขอบคุณครับ</p><ul><li><a href="https://medium.com/@nutdanai.vankrua/git-%E0%B9%80%E0%B8%A3%E0%B8%B4%E0%B9%88%E0%B8%A1%E0%B8%95%E0%B9%89%E0%B8%99-project-%E0%B9%83%E0%B8%AB%E0%B8%A1%E0%B9%88-b968939c6f61">Part 2: เริ่มต้น Project ใหม่และตั้งค่า Git</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9234c0dc66a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift iOS อ่าน File อย่งไร]]></title>
            <link>https://medium.com/odds-team/%E0%B8%AD%E0%B9%88%E0%B8%B2%E0%B8%99-file-%E0%B9%83%E0%B8%99%E0%B9%80%E0%B8%84%E0%B8%A3%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%87-iphone-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-swift-437a382c9919?source=rss-1dfd46d31bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/437a382c9919</guid>
            <category><![CDATA[ios-11]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[file-management]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Nutdanai Vankrua]]></dc:creator>
            <pubDate>Tue, 29 Jan 2019 16:51:59 GMT</pubDate>
            <atom:updated>2025-05-12T09:08:18.826Z</atom:updated>
            <content:encoded><![CDATA[<h3>Swift iOS อ่าน file อย่างไร</h3><p><em>เรื่องราวของ Dev ที่มี Requirement ให้ไปดึงไฟล์ .pdf / .docx / .rtf / .txt และอื่นๆ มากมายที่อยู่บนเครื่อง iPhone/iPad</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U2Bfd9mmiCzw3iunYyKpXQ.png" /><figcaption>Files App ใน iOS 11</figcaption></figure><p>ใน iOS 11 มี App ตัวใหม่ชื่อว่า “Files” คอยจัดการเรื่อง File ต่างๆ ให้ไม่ว่าจะอยู่บนเครื่อง หรืออยู่บน iCloud ก็ตาม</p><p>เราลองโหลด File อะไรก็ได้มาไว้ที่เครื่อง iPhone จะเจอ Default PopUp ของ iOS ถามว่าจะ Share ไปที่ไหน ซึ่งแน่นอน เราจะเลือก “<strong><em>Save to Files”</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*b_lmWN7HjTphLX-RI4cyCw.png" /><figcaption>หน้าตา Action Sheet ของการ Share</figcaption></figure><p>กด <strong><em>“Save to Files”</em></strong> มันก็จะถามต่อไปว่าจะให้ Save ใน App ไหน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*1jj5KtnK4J7HF1Ywq9GBIw.png" /><figcaption>เลือก App ที่ต้องการนำไฟล์ไปไว้ในเครื่อง</figcaption></figure><p>บางคนอาจสงสัยว่า ถ้าเป็นเช่นนี้ File ที่เก็บอยู่ใน App เรา App อื่นจะเห็นไหม คำตอบคือเห็นถ้าเราเก็บไว้ใน Folder <strong>“Documents”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*4m4WvTu-3Jya3Dqzgl9LLQ.png" /><figcaption>iOS File System</figcaption></figure><ul><li><strong>Documents</strong> : สำหรับเก็บไฟล์หรือข้อมูลที่ให้ User เห็นได้ หรือต้องการให้ App อื่น ซึ่งสามารถเห็นผ่าน Sharing ของ iOS ได้</li><li><strong>Library</strong> : สำหรับ Folder นี้จะไม่เปิดเผยให้ User เห็น แต่ก็ไม่ได้ความว่าให้เก็บข้อมูล User นะครับ</li><li><strong>Temp</strong> : สำหรับเก็บข้อมูลชั่วคราวและไม่เปิดเผยให้ User เห็น ซึ่งถ้า App เราปิดอยู่ File ใน Folder นี้สามารถถูกลบจาก OS โดยอัติโนมัติได้</li></ul><p>สามารถอ่านเพิมเติ่มได้ที่นี้นะครับ</p><p><a href="https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html">https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html</a></p><h3>กลับมาที่โจทย์ของเรา (ลง Code กันสักที)</h3><p><em>เราอยากที่จะสามารถ Browse ไฟล์ที่อยู่บนเครื่องเราได้ ดึง Path มันมาได้ เพื่อที่จะทำอะไรบางอย่างต่อ ค่อยว่ากันไป ทำอย่างไรนะ</em></p><p>โชคดีที่ Apple มี ViewController ชื่อว่า <strong><em>“UIDocumentInteractionController” </em></strong>มาให้ ง่ายๆ เลยก็สั่งให้เปิด ViewController นี้ขึ้นมาเลย</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef36ae1ad86ddec62801bdb3c9868030/href">https://medium.com/media/ef36ae1ad86ddec62801bdb3c9868030/href</a></iframe><p>จะสังเกตว่าต้องระบุประเภทไฟล์ที่เราสนใจด้วย (<strong><em>documentTypes</em></strong>) ในกรณีนี้เราสนใจไฟล์ทุกประเภทจึงส่งไปว่า <strong><em>“public.item”</em></strong></p><p>เราสามารถดูได้ว่า <strong><em>“UIDocumentInteractionController”</em></strong> รับ <strong><em>“documentType”</em></strong> อะไรได้บ้างจากที่นี้เลย <a href="https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html">https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html</a></p><p>สุดท้ายนี้เราต้องมี Listener / Callback / etc. อะไรบางอย่างที่ให้ <strong><em>“UIDocumentInteractionController”</em></strong> กลับมาบอกเราได้ว่าเลือกไฟล์อะไรไป ในกรณีนี้จะเป็น Delegate (หาอ่านต่อเองนะ &gt;..&lt;)</p><p>Class ViewController ของเราจึง implement Protocol ชื่อว่า <strong><em>“UIDocumentPickerDelegate”</em></strong> และสามารถคอยฟัง URL Path ของ File จาก Function ตาม Code ตัวอย่างได้แล้ว :)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa28d70d29c334594f598f22425f870a/href">https://medium.com/media/aa28d70d29c334594f598f22425f870a/href</a></iframe><h3>จบแล้ว (หรือเปล่านะ)</h3><p>จริงๆ แล้วยังมีหลายเรื่องที่สามารถนำไปต่อยอดได้ เช่น Upload File จากไฟล์ที่อ่าน / อ่านไฟล์ขึ้นมาแก้ไขข้อมูล แล้วบันทึกกลับลงไปใหม่ และอื่นๆ มากมาย แต่ในบทความนี้ขอจบเฉพาะ Browse File ให้เจอก่อนนะครับ</p><p>ถ้าใครอยากได้ Series การจัดการ File ในเครื่อง iOS ต่อช่วยกันตบมือด้วยนะครับ แล้วผมจะต่อยอดและมาเล่าให้ฟัง</p><p>ไว้เจอกันใหม่… ขอบคุณครับ ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=437a382c9919" width="1" height="1" alt=""><hr><p><a href="https://medium.com/odds-team/%E0%B8%AD%E0%B9%88%E0%B8%B2%E0%B8%99-file-%E0%B9%83%E0%B8%99%E0%B9%80%E0%B8%84%E0%B8%A3%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%87-iphone-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-swift-437a382c9919">Swift iOS อ่าน File อย่งไร</a> was originally published in <a href="https://medium.com/odds-team">odds.team</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>