Save 37% off PRO during our Black Friday Sale! »

クライアント型iOSアプリのつくりかた

 クライアント型iOSアプリのつくりかた

5287c9b9576749092d3170ec738338b8?s=128

Yusuke Ito

May 25, 2013
Tweet

Transcript

  1. ΫϥΠΞϯτܕiOSΞϓϦ ͷͭ͘Γ͔ͨ Yusuke Ito, @novi_, Github: novi at ୈ4ճ iphone_dev_jp

    ౦ژiPhone/Macษڧձ
  2. About me http://about.me/yusukeito @novi_, Github: novi ߴઐଔۀޙϑϦʔ WebͷελʔτΞοϓ͍͔ͭ͘ UI, UX

    ͱ Cocoa(iOS)ͱMac 7೥͘Β͍
  3. Agenda ࣮૷ྫ(Githubͷίʔυ) MVCͱσβΠϯύλʔϯ ։ൃϓϩηε

  4. ໨త খ͍͞νʔϜ(2,3ਓ)Ͱ ৽نiOSΞϓϦΛ ޮ཰ྑ͘ɺ҆શʹɺ଎͘ ͭ͘Δ͜ͱΛ໨తͱ͢Δɻ (৽نࣄۀ΍ελʔτΞοϓΛλʔήοτ)

  5. ࣮૷ྫͱͻͳܗ LTAPIRequest Google it or https://github.com/novi/LTAPIRequest ࣮૷͸ίʔυࢀর iOS(Cocoa)ͷMVCʹ͍ͭͯษڧ͢ΔͨΊ ϑϨʔϜϫʔΫΛ࢖Θͳ͍৔߹ͷ࣮૷ྫΛఏڙ͢Δ ͨΊ

  6. (σβΠϯ)ύλʔϯ ܦݧଇ͔ΒಘΒΕͨ͏·͍͘͘ͱࢥΘΕΔߟ͑ํͱ ࣮૷ ਖ਼ղ΍ෆਖ਼ղ͸ແ͍ Ϋϥεͷઃܭํ๏ɺΦϒδΣΫτͷࢀরؔ܎΍஋ͷ ࣋ͨͤํɺΛ޻෉ͯ͠ޮ཰ྑ͘ɺಡΈ΍͘͢ɺ͢Δ

  7. ϑϨʔϜϫʔΫͱϥΠϒϥϦ ϥΠϒϥϦ΍ϑϨʔϜϫʔΫ͸Ϋϥε(.m)ͷू·Γ ϑϨʔϜϫʔΫ͸࣮૷(.m)ʹՃ͑ͯઃܭ΍σβΠϯύ λʔϯͷҙຯ߹͍͕ՃΘΔ e.g.) UIKit=ϑϨʔϜϫʔΫ=MVC͕͋Δ ϑϨʔϜϫʔΫͷϧʔϧʹैͬͯΞϓϦΛ࡞Δ e.g.) -layoutSubviews ͕ݺ͹ΕͨΒxx͢Δ

  8. http://www.flickr.com/photos/naotakem/4570128498 σβΠϯύλʔϯͷॏཁੑ

  9. σβΠϯύλʔϯͷ໨త ఻͑΍͍͢ίʔυΛॻ͘ʹಡΈ΍͍͢ ૊Έ׵͑΍͍͢ίʔυΛॻ͘ ఔΑ݁͘߹͞Ε͍ͯΔ(ີͰ΋ૈͰ΋ͳ͍தؒ) ϦϑΝΫλϦϯά͠΍͍͢ ςετ͠΍͍͢ मਖ਼͠΍͍͢ ॻ͘ͷʹख͕͔͔ؒΒͳ͍

  10. iOS MVC Webͱҧͬͯεςʔτϑϧ(not εςʔτϨε) Model-View-ViewController (MVC)

  11. MVCͱ͸ Model View View Controller ߋ৽ ߋ৽ มߋ ίϯτϩʔϥ͕શମͷϑϩʔΛ੍ޚ มߋ

  12. iOS, UIKitͰ͸... Model View Controller UIViewController, UINavigationController... NSString, NSDictionary, NSArray...

    UIView, UITableView...
  13. UIKitجຊύλʔϯ ௨஌(NSNotificationCenter) σϦήʔτ(NSTableViewDelegateͳͲ) λʔήοτɾΞΫγϣϯ(UIControlͳͲ, -addTarget:) Ωʔ஋؂ࢹ(Key-Value-Observing) ※͢΂ͯObjective-Cͷݴޠ࢓༷Ͱ͸ͳ͘ɺ ύλʔϯͷҰछ KVO͸ඍົ͚ͩͲ...

  14. Case Study อ͔࣋Βߟ͑Δ ΦϒδΣΫτ͕ΦϒδΣΫτΛอ࣋͢Δ/͠ͳ͍ ͱ͍͏͜ͱ(ʹࢀরΛ࣋ͭ, Reference) ʹ͍ͭͯϧʔϧΛ࡞Δ ඞવతʹσβΠϯύλʔϯ͕ཁΔɾߟ͑Δ ϧʔϧΛ࡞Ε͹ͦͷϧʔϧΛલఏʹͤ͟ΔΛಘͳ͍ ϧʔϧʹσβΠϯύλʔϯͰ΋͍͍

  15. ࠶ͼModel-View-ViewController Model: NSObject͔Β࡞Δ, NSDictionary, NSArray... View: UIViewͷαϒΫϥε͢΂ͯ(UITableView, UIButton, UIScrollView...) ViewController:

    UIViewController, UINavigationViewController, UITabViewController...
  16. Model-View-ViewController ͦΕͧΕ͕࣋ͭ΂͖΋ͷ࣋ͭ΂͖ Ͱͳ͍΋ͷ ໼ҹ=อ࣋(ࢀর)

  17. ViewΛ࣋ͭ ModelΛ࣋ͭ Model Controller View ViewController͔Βݟͯ...

  18. Model Controller View × × Model͔Βݟͯ... View͸࣋ͨͳ͍ ViewController΋࣋ͨͳ͍

  19. ViewController͸࣋ͨͳ͍ ModelΛ࣋ͭ Model Controller View × View͔Βݟͯ...

  20. Model Controller View ࠶ͼ: อ͔࣋Βߟ͑Δ ·ͱΊ

  21. Model Controller View Ͳ͏΍ͬͯࢀরͷແ͍ΦϒδΣΫτಉ࢜ ͷϝιουΛݺͼग़͔͢ σϦήʔτ Target-Action ௨஌ KVO Callback

    ϝιου (ϝοηʔδૹ৴)
  22. Case Study2 ViewControllerͷ࢓ࣄ͔Βߟ͑Δ ViewController͕͢Δ͜ͱɺ͠ͳ͍͜ͱΛϧʔϧԽ͢Δ ඞવతʹσβΠϯύλʔϯ͕ཁΔɾߟ͑Δ ϧʔϧΛ࡞Ε͹ͦͷϧʔϧΛલఏʹͤ͟ΔΛಘͳ͍ ϧʔϧʹσβΠϯύλʔϯͰ΋͍͍

  23. ViewController͕͢Δ͜ͱ NSNotificationCenter͔Β௨஌Λड͚औΔ KVOͰ௨஌Λड͚औΔ ModelΛอ࣋͢Δ ViewʹModelΛ౉͢(setModelName:΍DataSourceܦ༝Ͱ) ViewΛੜ੒(ΠϯελϯεԽ)͢Δ ViewͷΠϕϯτΛड͚औΔ(Target-Action΍Delegate͔Β)

  24. ViewController͕͠ͳ͍͜ͱ ωοτϫʔΫ͔ΒσʔλΛऔಘ͢Δ(ϦΫΤετͨ͠ ޙɺ௨஌΍σʔλΛ௚઀ड͚औΔ) σΟεΫʹอଘ͢Δ σʔλΛอ࣋͢Δ ೖྗ͞Εͨσʔλͷ஋͕ਖ਼͍͔͠ݕূ͢Δ (Ҏ্͢΂ͯModel͕୲౰͢Δ)

  25. σϦήʔτͷॻ͖͔ͨ ࠶ͼ: σϦήʔτ͸ύλʔϯ delegateͱ͍͏໊લΛΑ͘࢖͏ dataSource΋σϦήʔτͷύλʔϯ UITableView΍UIScrollViewͷॻ͖͔ͨΛࢀߟʹ͢Δ

  26. Target-Actionͷॻ͖͔ͨ ࠶ͼ: ͜Ε΋ύλʔϯ UIResponderΛܧঝ(Responder-Chainύλʔϯ) UIView΍UIViewController͸UIResponderΛܧঝ ૹΔଆ(View): UIButton(<=UIControl) - addTarget:action:forControlEvents: TargetΛnilʹ͢Δ

    ड͚ͱΔଆ(Controller): ↑Ͱ࣮૷ͨ͠actionͷϝιουΛ࣮૷͢Δ - (void)someAction:(id)sender
  27. ։ൃϓϩηε ໨తͷͨΊʹiOSΞϓϦͷ։ൃϓϩηεʹ͍ͭͯύλ ʔϯԽͯ͠ΈΔ ։ൃϓϩηεͷύλʔϯ

  28. ໨త খ͍͞νʔϜ(2,3ਓ)Ͱ ৽نiOSΞϓϦΛ ޮ཰ྑ͘ɺ҆શʹɺ଎͘ ͭ͘Δ͜ͱΛ໨తͱ͢Δɻ (৽نࣄۀ΍ελʔτΞοϓΛλʔήοτ)

  29. ։ൃϓϩηε ՝୊ ਓؒతͳ੍໿(ݸੑɺٕೳϨϕϧɺϞνϕʔγϣ ϯɺ࢓ࣄελΠϧ)ΛͲ͏৐Γӽ͑Δ͔? աఔͰνʔϜΛҭͯΔ͜ͱ͕Ͱ͖Δ͔ աఔͰจԽΛ࡞Δ͜ͱ͕Ͱ͖Δ͔

  30. ෼୲ ίʔσΟϯά 1 or 2ਓ ྫ͑͹, Storyboard, ViewControllerͷਓ Model, View,

    Utils, Manager, Networkͷਓ Ϟδϡʔϧ͝ͱ෼͚Δ
  31. ։ൃ؅ཧ ։ൃϑϩʔΛνʔϜ಺Ͱཱ֬͢Δ ࿈བྷखஈ νϟοτϫʔΫ etc.... ࢖༻ϑϨʔϜϫʔΫɺϥΠϒϥϦ υΩϡϝϯτ΍Issue؅ཧγεςϜ Google Docs, Github

    Issues, Pivotal Tracker, etc...
  32. ϑΟʔυόοΫ UXͷίΞʹͳΔେࣄͳػೳΛ଎͘࡞Δ த్൒୺ʹಈ͔ͳ͍ػೳΛͩΒͩΒ࣮૷͠ͳ͍ ग़དྷͨΒɺϦϦʔε͢Δ (νʔϜ಺orςελʔ) ػೳΛϨϏϡʔ͢Δ

  33. υΩϡϝϯτ ίʔυͱಉ͡Α͏ʹෛ࠴Ͱ͋Δ υΩϡϝϯτͷ੹೚ ࡞੒ऀ͕Ξοϓσʔτ͢Δ੹೚Λ࣋ͭ ࡞੒ऀ͕੹೚Λ࣋ͨͳ͘ͳΔ৔߹͸յ͢ ΨΠυϥΠϯ·ͨ͸ςϯϓϨʔτΛ࡞੒

  34. UIσβΠϯ ඞͣ૝ఆ͞ΕΔ࣮σʔλΛ࢖༻ UX, UI͕ᐆດͳঢ়ଶͰ͸ϑϧػೳΛ࣮૷͠ͳ͍ จݴ΋࠷ॳ͔ΒͪΌΜͱߟ͑Δ

  35. ࣮૷ͷઃܭ কདྷ࣮૷͢Δ͔΋͠Εͳ͍ػೳͷઃܭ΋͢Δ ͨͩ͠ɺ࠷ॳͷϦϦʔεͰ͸γϯϓϧͳػೳ ʹߜΔ ࣮ࡍʹςετίʔυΛॻ͔͘ʹؔΘΒͣςετ ͢ΔલఏͰઃܭ͢Δ(ςετ͠΍͍͢ઃܭ) ઌΛݟ͗ͨ͢ઃܭΛ͠ͳ͍ HTTP API, UI...,

    Ϋϥε
  36. ίʔσΟϯά ΨΠυϥΠϯΛ࡞੒ ίʔυϨϏϡʔ pull࣌ʹߦ͏ɺఆظతʹߦ͏(optional) DRY (Don’t Repeat Yourself) ͨͩ͠ҙࣝ͗͢͠ͳ͍ ϞδϡʔϧԽɺΫϥεԽ

  37. όʔδϣϯ؅ཧ ϒϥϯνΛ੾Γ͗͢ͳ͍ Storyboard͕ϚʔδͰ͖ͳ͍ 1ਓ͔͠৮Βͳ͍ͳͲ ϏϧυͰ͖ͳ͍ίʔυɺςετ(खorϓϩάϥϜ Ͱ)͍ͯ͠ͳ͍ίʔυ͸ίϛοτ͠ͳ͍ ίϛοτϩάͷΨΠυϥΠϯΛ࡞੒

  38. ֎෦ϥΠϒϥϦ ࢖͍͗͢ͳ͍ (Pods͸ศར͚ͩͲ...) 1ػೳ͚͔ͩ͠࢖Θͳ͍ͷʹશ෦ೖΕͳ͚Ε͹ ͳΒͳ͍΋ͷͳͲ→୅ସΛ୳͢orࣗ෼Ͱॻ͘ ෭࡞༻ͷ͋Δ΋ͷ͸࢖༻͠ͳ͍ ϝιουೖΕସ͑Λ͍ͯ͠Δ΋ͷͳͲ ίʔυ͕௥͑ͳ͍΋ͷ͸࢖༻͠ͳ͍

  39. APIϑΝʔετ αʔϏεΛఆٛ (αʔόαΠυͷػೳɾ࢓༷) RESTful API(=υΩϡϝϯτ)Λఆٛ αʔόʔαΠυͷϞοΫΛ࡞Δ(optional) ΫϥΠΞϯταΠυΞϓϦΛॻ͘ RESTful API ͷςετΛॻ͘

    αʔόʔαΠυΛ࣮૷͢Δ
  40. None