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

iOS App デザインパターン 基礎編

iOS App デザインパターン 基礎編

5287c9b9576749092d3170ec738338b8?s=128

Yusuke Ito

February 20, 2012
Tweet

Transcript

  1. iOS App σβΠϯύλʔϯ #1 Yusuke Ito

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

  3. σβΠϯύλʔϯͷॏཁੑ ϑϨΩγϒϧɾָʹมߋՄೳ Ϧʔϯ(ΞδϟΠϧ)։ൃָ͕ʹ ίʔυͷՄಡੑͷ޲্ εύήοςΟԽͷ๷ࢭ ύϑΥʔϚϯεͷ޲্ɾϝϞϦϦʔΫͷ๷ࢭ ...͕ظ଴Ͱ͖Δ

  4. iOS AppͷΞʔΩςΫνϟ Model-View-Controller(MVC)Λ౿ऻ Rails(Ruby)౳ͷαʔόαΠυWebΞϓϦͱ͸શ͘ҧ͏ (WebΞϓϦ→iOS΁Ҡߦͷਓ͸஫ҙ) Կ͕Ұ൪͍͔ۙ→NextSTEP ͦΜͳ΋Μ஌Δ͔!! iOSͷจԽΛ஌Δඞཁ͕͋Δɻ MVCվΊModel-View-ViewController

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

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

    UIView, UITableView...
  7. Bad pattern #1 Model Controller View View View View Controller

    Controller Controller View View View Model Model Model Model Model
  8. Bad pattern #2 View View View View View View View

    Model Model Model Model Model Model Controller View View
  9. Better pattern Model Controller View Model Controller View Model Controller

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

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

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

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

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

  15. ViewController͸࣋ͨͳ͍ Model͸جຊ࣋ͨͳ͍ Viewʹදࣔ͢Δඞཁ͕͋Δ ΋ͷ͚ͩ࣋ͭ Model Controller View × × View͔Βݟͯ...

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

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

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

    (ϝοηʔδૹ৴)
  19. σϦήʔτͷॻ͖͔ͨ ࠶ͼ: σϦήʔτ͸ύλʔϯ delegateͱ͍͏໊લΛΑ͘࢖͏ dataSource΋σϦήʔτͷύλʔϯ UITableView΍UIScrollViewͷॻ͖͔ͨΛࢀߟʹ͢Δ

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

    ड͚ͱΔଆ(Controller): ↑Ͱ࣮૷ͨ͠actionͷϝιουΛ࣮૷͢Δ - (void)someAction:(id)sender
  21. σβΠϯύλʔϯͷशಘ ʹจষͱಉ͡ ಡΉ: ࣗ෼ͷίʔυɾGithub(ଞਓ)ͷίʔυɾࣗ෼ͷ աڈͷίʔυ ॻ͘: ίʔσΟϯάɾϦϑΝΫλϦϯάɾ৭ʑͳύ λʔϯΛࢼ͢

  22. ͓͢͢Ί৘ใݯ Apple ެࣜυΩϡϝϯτ WWDC2010-2011 ϏσΦͱεϥΠυ Dynamic Objective-C / ໦Լ ੣

    / ຊ iOS։ൃʹ͓͚ΔύλʔϯʹΑΔΦʔτϚςΟζϜ / ໦Լ ੣ / ຊ
  23. εϥΠυ http://bit.ly/xZ7NsF ίʔσΟϯάΨΠυϥΠϯͷ࿩ http://yusukeito.me/post/16447745113 https://github.com/novi Thank You ‼