Upgrade to Pro — share decks privately, control downloads, hide ads and more …

編集距離による UITableViewの差分更新 - potatotips #37

6500a96a5f0786d7ff0c53429d691ae6?s=47 kazuhiro4949
February 15, 2017
3.1k

編集距離による UITableViewの差分更新 - potatotips #37

デモで使ったサンプルコードはこちら
https://github.com/kazuhiro4949/EditDistanceSample

6500a96a5f0786d7ff0c53429d691ae6?s=128

kazuhiro4949

February 15, 2017
Tweet

Transcript

  1. ฤूڑ཭ʹΑΔ 6*5BCMF7JFXͷࠩ෼ߋ৽ QPUBUPUJQT ,B[VIJSP)":"4)*

  2. ࣗݾ঺հ w ྛ࿨߂ !LB[VIJSP  w :BIPP+"1"/$PSQPSBUJPO w J04"QQ&OHJOFFS

  3. 6*5BCMF7JFXߋ৽໰୊ w SFMPBE3PXT"U*OEFY1BUITͳͲͷࠩ෼ߋ৽͸ ѻ͍͕೉͘͠ɺΫϥογϡͷԹচʹͳΓ͕ͪ w ҰํͰSFMPBE%BUBͰߋ৽͢Δͱը໘͕ΧΫͭ ͍ͯ͠·͏

  4. ࠩ෼ߋ৽͕ѻ͍ʹ͍͘ݪҼ w ίʔυ͕ෳࡶԽͯ͘͠Δͱσʔλͷߋ৽ͱը໘ ͷߋ৽͕טΈ߹Θͳ͘ͳΔ w Ҿ͖ܧ͗Ͱطଘͷ6*5BCMF7JFX΍ 6*$PMMFDUJPO7JFX΁௥Ճ࣮૷ͨ͠ͱ͖ͳͲ w ωοτϫʔΫ͔ΒऔΕͨλΠϛϯάͰॱ࣍ը ໘΁൓өͤ͞Δ৔߹ͳͲ

  5. ࠩ෼ߋ৽Λ҆શʹऔΓѻ͍͍ͨ

  6. *OTUBHSBN੡ͷ 6*$PMMFDUJPO7JFXϥΠϒϥϦ

  7. *OTUBHSBN੡ͷ 6*$PMMFDUJPO7JFXϥΠϒϥϦ ߋ৽ͷศརػೳ͕ϝΠϯѻ͍ʹͳ͍ͬͯΔ

  8. ଞʹ΋ࠩ෼ߋ৽Λѻ͍ͬͯΔ ϥΠϒϥϦ͸͍͔ͭ͋͘Δ w IUUQTHJUIVCDPNLIBOMPV/4"SSBZ -POHFTU$PNNPO4VCTFRVFODF w IUUQTHJUIVCDPNPTUFTMBH$IBOHFTFU w IUUQTHJUIVCDPNKqJOUFS%XJ⒎U

  9. ͦΕΒ͸ڞ௨ͷ΍ΓํͰɺ σʔλͷߋ৽ϓϩηεΛܗࣜԽ͍ͯ͠Δ

  10. ܗࣜԽͯ҆͠શੑΛ্͛Δ ߋ৽ޙͷ഑ྻΛੜ੒ ߋ৽લ഑ྻͱͷEJ⒎Λܭࢉ EJ⒎Λ6*ͷࠩ෼ߋ৽ॲཧ΁ม׵

  11. ܗࣜԽͯ҆͠શੑΛ্͛Δ ߋ৽ޙͷ഑ྻΛੜ੒ ߋ৽લ഑ྻͱͷEJ⒎Λܭࢉ EJ⒎Λ6*ͷࠩ෼ߋ৽ॲཧ΁ม׵

  12. ܗࣜԽͯ҆͠શੑΛ্͛Δ ߋ৽ޙͷ഑ྻΛੜ੒ ߋ৽લ഑ྻͱͷEJ⒎Λܭࢉ EJ⒎Λ6*ͷࠩ෼ߋ৽ॲཧ΁ม׵

  13. ܗࣜԽͯ҆͠શੑΛ্͛Δ ߋ৽ޙͷ഑ྻΛੜ੒ ߋ৽લ഑ྻͱͷEJ⒎Λܭࢉ EJ⒎Λ6*ͷࠩ෼ߋ৽ॲཧ΁ม׵

  14. ਤࣔ͢Δͱ ݱࡏͷσʔλྻ ߋ৽ޙσʔλྻ EJ⒎ΛऔΔ 6*ߋ৽ίʔυʹม׵͢Δ

  15. ਤࣔ͢Δͱ EJ⒎ΛऔΔ 6*ߋ৽ίʔυʹม׵͢Δ ݱࡏͷσʔλྻ ߋ৽ޙσʔλྻ

  16. %J⒎ΛऔΔͨΊʹඞཁͳ͜ͱ ʹ ฤूڑ཭ͷܭࢉ

  17. ฤूڑ཭ ͭͷจࣈྻͷؒͰɺҰํͷจࣈྻΛ΋͏Ұํͷจ ࣈྻʹ͢Δͷʹඞཁͳɺૠೖɾ࡟আɾஔ׵ͷ࠷খ ճ਺ "MHPSJUINTPO4USJOHT 5SFFTBOE4FRVFODFT$PNQVUFS4DJFODFBOE$PNQVUBUJPOBM#JPMPHZ

  18. ฤूڑ཭ͷ ܭࢉΞϧΰϦζϜ w ಈతܭը๏ w .BZFSͷΞϧΰϦζϜ w 8VͷΞϧΰϦζϜ w FUD

  19. ฤूڑ཭ͷ ܭࢉΞϧΰϦζϜ w ಈతܭը๏ w .BZFSͷΞϧΰϦζϜ w 8VͷΞϧΰϦζϜ w FUD

    ͦΕͧΕܭࢉྔ͕ҟͳΔ / .ʜ഑ྻ௕ %ʜฤूڑ཭ 1ʜ࡟আ਺ ʜɹɹ0 /. ʜɹɹ0 /% ʜɹɹ0 /1
  20. w ಈతܭը๏ w .BZFSͷΞϧΰϦζϜ w 8VͷΞϧΰϦζϜ w FUD ࠓճ͸8VͷΞϧΰϦζϜΛ࣮૷͢Δ ฤूڑ཭ͷ

    ܭࢉΞϧΰϦζϜ ʜɹɹ0 /. ʜɹɹ0 /% ʜɹɹ0 /1
  21. 8VͷΞϧΰϦζϜ֓ཁ w ߋ৽લΛY ޙΛZ࣠ʹฒ΂ Δ w ॎҠಈ͸શͯ࡟আɾԣ͸શ ͯ௥ՃͱͳΔ w Ҡಈ͠ͳ͕ΒӈԼ·Ͱͷܦ

    ࿏Λܭࢉ IUUQHJIZPKQEFWDPMVNOQSPHEJ⒎@TE QBHF
  22. 8VͷΞϧΰϦζϜ֓ཁ w %Ў 1 w %͸ฤूڑ཭ɾЎ͸഑ྻ௕ ͷࠩɾ1͸࡟আ਺ w ୳ࡧൣғ͸࣮࣭Ұ෦ʹߜΕ Δ

    IUUQHJIZPKQEFWDPMVNOQSPHEJ⒎@TE QBHF
  23. ࣮૷ &EJU%JTUBODF$BMDVMBUPS ഑ྻ͔Βڑ཭ܭࢉ &EJU%JTUBODF$POWFSUFS ܭࢉ݁Ռ͔Βߋ৽ॲཧΛੜ੒ 6*5BCMF7JFX ߋ৽લ"SSBZ5 ߋ৽ޙ"SSBZ5 "SSBZ4FT5 ֤ཁૉͷ௥Ճɾ࡟আɾҰக৘ใ

    ೖྗ ೖྗ ܭࢉ݁ՌΛग़ྗ ฤू৘ใΛೖྗ 6*5BCMF7JFXͷߋ৽Λ࣮ߦ
  24. ࣮ࡍʹܭࢉͯ͠ΈΔ  // ݱࡏςʔϒϧʹදࣔ͞Ε͍ͯΔσʔλ var currentSource = ["a", "b", "c",

    "d", "e"] // ৽͘͠ද͍ࣔͨ͠σʔλ let newSource = ["a", "b", "c", "d", "h", "e", "f", "g"] // ฤूڑ཭ͷܭࢉͯ͠ɺҎԼͷΑ͏ͳσʔλߏ଄Λߏங // let ses = [ // Ses<String>(edit: EditDistance.Edit.common, c: "a", index: 0), // Ses<String>(edit: EditDistance.Edit.common, c: "b", index: 1), // ... // Ses<String>(edit: EditDistance.Edit.add, c: "e", index: 4), // ... // ] let editDistance = EditDistanceCalculator(from: currentSource, to: newSource) let ses = editDistance.compose()
  25. // ςʔϒϧߋ৽ॲཧ͕ೖͬͨҎԼͷܗͷΫϩʔδϟΛ  Ͱ࡞ͬͨܭࢉ݁Ռ TFT ͔Βߏங // let updateHandler =

    { (tableView: UITableView) in // tableView.beginUpdates() // tableView.insertRows(at: [IndexPath(row: 4, section: 0)], with: .fade) // tableView.insertRows(at: [IndexPath(row: 6, section: 0)], with: .fade) // tableView.insertRows(at: [IndexPath(row: 7, section: 0)], with: .fade) // tableView.endUpdates() // } let updateHandler = EditDistanceConverter.convertToTableView(from: ses) // σʔλιʔεΛஔ͖׵͑ͯߋ৽Λ࣮ߦ currentSource = newSource updateHandler(tableView) ࣮ࡍʹܭࢉͯ͠ΈΔ 
  26. σϞ 6*5BCMF7JFXͰϥϯμϜʹσʔλΛߋ৽ 6*$PMMFDUJPO7JFXͰϥϯμϜʹσʔλΛߋ৽

  27. ࠓޙͷ༧ఆ w ࣍ݩ഑ྻʹରԠ w ΞϧΰϦζϜຖʹܭࢉ࣌ؒͷ࣮ଌ஋ΛऔΔ w ΞϧΰϦζϜΛࠩ͠ସ͑ΒΕΔΑ͏ʹͯ͠ϥΠϒ ϥϦԽ

  28. ·ͱΊ w ฤूڑ཭ʹΑͬͯ6*5BCMF7JFX 6*$PMMFDUJPO7JFX ͷࠩ෼ߋ৽ΛܗࣜԽͰ͖Δ w σʔλιʔεͷ؅ཧΛߟ͑Δෛ୲͕ݮΔ w ز͔ͭͷ044Ͱ΋औΓೖΕΒΕ͍ͯΔϝδϟʔͳ ํ๏

    w ͜ͷ༻్Ͱ͋Ε͹͜ͷΞϧΰϦζϜ͕Ұ൪͍͍ɺ ͳͲ͋Ε͹ڭ͍͑ͯͩ͘͞N @@ N
  29. σϞ༻ʹ࡞ͬͨίʔυ͸ ͪ͜Β΁ஔ͍ͯ·͢ IUUQTHJUIVCDPNLB[VIJSP&EJU%JTUBODF4BNQMF

  30. ࢀߟࢿྉ w *OTUBHSBN*(-JTU,JU IUUQTHJUIVCDPN*OTUBHSBN*(-JTU,JU  w LIBOMPV/4"SSBZ-POHFTU$PNNPO4VCTFRVFODF IUUQTHJUIVCDPNLIBOMPV/4"SSBZ -POHFTU$PNNPO4VCTFRVFODF 

    w PTUFTMBH$IBOHFTFU IUUQTHJUIVCDPNPTUFTMBH$IBOHFTFU  w KqJOUFS%XJ⒎U IUUQTHJUIVCDPNKqJOUFS%XJ⒎U  w &EJUEJTUBODFBOEFEJUTUFQT IUUQEBWFEFMPOHUVNCMSDPNQPTUFEJU EJTUBODFBOEFEJUTUFQT  w %J⒎BMHPSJUIN IUUQDPOTUFMMBUJPOIBUFOBCMPHDPNFOUSZ  w EJ⒎ͷಈ࡞ݪཧΛ஌ΔʙͲͷΑ͏ʹͯࠩ͠෼Λಋ͖ग़͢ͷ͔ IUUQXXXUIFXPSLqPXDPN IPNFTJOPLBJGBIVBOKJOHEJ⒎OPEPOH[VPZVBOMJXP[IJSVEPOPZPVOJTIJUFDIBGFOXP EBPLJDIVTVOPLB  w 48.BOFS (.ZFST 8.JMMFS "O0 /1 4FRVFODF$PNQBSJTPO"MHPSJUIN