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

実践RubyMotion

 実践RubyMotion

RubyMotion Kaigi 2013 での発表資料です

B4afc7d853d7f1cb6a253d3c7183c05a?s=128

Naoya Ito

May 29, 2013
Tweet

More Decks by Naoya Ito

Other Decks in Technology

Transcript

  1. ࣮ફ3VCZ.PUJPO ΞϓϦ։ൃऀͷࢹ఺͔Β  !OBPZB@JUP

  2. )#'BWX3VCZ.PUJPO

  3. ʊਓਓਓਓਓਓਓʊ ʼɹಥવͷ಴࠳ɹʻ ʉY^Y^Y^Y^Y^Yʉ (༁: ୯ʹ్தͰΊΜͲ͘ͳ͚ͬͨͩ)

  4. 4JHOBMTNFFUT3VCZ.PUJPO

  5. 3VCZ.PUJPO͸͕͜͜ҧ͏ •  0CKFDUJWF$3VOUJNFͷ্ʹ࣮૷͞Εͨ3VCZ –  ϒϦοδͰ͸ͳ͍ –  ଎͍ –  0CKFDUJWF$ͳ࣮૷ͱ௚઀ϦϯΫͰ͖Δ

  6. None
  7. class  HelloViewController  <  UIViewController      def  viewDidLoad    

         super            self.view.backgroundColor  =  UIColor.whiteColor            @label  =  UILabel.new          @label.frame  =  [[10,  10,],  [320,  20]]          @label.text    =  "Hello,  World!”            self.view.addSubview(@label)      end   end
  8. Α͋͘Δ࣭໰ •  ʮ0CKFDUJWF$Θ͔Βͳͯ͘΋։ൃͰ͖·͔͢ ʯ •  ͸͍ɺେৎ෉Ͱ͢

  9. ͨͩ͠ •  ͨͩ͠J04։ൃͷ஌ࣝ͸ඞཁͰ͢ !?

  10. $PDPB5PVDIͱ3VCZ.PUJPO •  0CKFDUJWF$͸ݴޠ㱺3VCZ •  J04։ൃ$PDPB5PVDIϑϨʔϜϫʔΫ –  ʮ0CKFDUJWF$Ͱ$PDPB5PVDIͷ"1*ΛݺͿʯ –  㱺ʮ3VCZͰ$PDPB5PVDIͷ"1*ΛݺͿʯ view.backgroundColor

     =  UIColor.whiteColor   view.addSubview(@label)   navigationController.pushViewController(c,  animated:true)  
  11. 3BJMT೴ͰJ1IPOFΞϓϦ͕࡞ΕΔ ͱࢥͬͨ 

  12. 3VCZ.PUJPOͷجຊΫϥε •  0CKFDUJWF$ϥϯλΠϜͷΫϥεʹͳ͍ͬͯΔ –  0CKFDU/40CKFDU (main)>  Object.new   =>  #<NSObject:0x9d478c0>

     
  13. Ώ͑ʹ •  ී௨ʹ3VCZͱͯ͠ॻ͚Δ UILabel.new.tap  do  |label|      label.text  =

     "Hello,  World!"   end     •  $PDPBͷ"1*͕ݺ΂Δ self.willChangeValueForKey('bookmarks')   ...   self.didChangeValueForKey('bookmarks')  
  14. ฒߦॲཧ΋͓खͷ΋ͷ •  (SBOE$FOUSBM%JTQBUDI Dispatch::Queue.concurrent.async  do      image  =  UIImage.alloc.initWithData(

             NSData.dataWithContentsOfURL(url.nsurl)      )        Dispatch::Queue.main.sync  do          @imageView.image  =  image      end   end  
  15. ϝϞϦ؅ཧ •  3VCZ.PUJPOಠࣗͷϝϞϦ؅ཧ࣮૷ –  OPU"3$ –  OPU3VCZT($ •  ϦϑΝϨϯεΧ΢ϯλํࣜ – 

    "3$෩ʹࣗಈͰBHFTBHF –  8FBL3FGFSFODF͋Γ 3VCZ.PUJPO͔Β  –  ʮ1FSMΈ͍ͨͳ΋ͷͩͱࢥ͑͹ྑ͍ʯʮ͑ͬʯ
  16. ͸·Βͳ͍3VCZ.PUJPO •  ʮϥΠϑλΠϜ͕௕ͦ͏ͳΦϒδΣΫτ͸Πϯελϯε ม਺ʹೖΕΔɻ͜Ε·Ί஌ࣝͳʯ @model  =  MyModel.new  

  17. 3VCZ.PUJPOͰ࠷΋େ੾ͳ͜ͱ

  18. &NBDTͰॻ͚Δ

  19. NPUJPONPEFFM

  20. source: www.rubymotion.com

  21. 3VCZ.PUJPOͱϥΠϒϥϦ

  22. wv  =  WebViewController.alloc.init   wv.url  =  'http://example.com'   navigationController.pushViewController(wv,  animated:true)

     
  23. ͤΊͯɺ Β ͠ ͘  3VCZ

  24. #  Rakefile   require  'rubygems'   require  'sugarcube'   navigationController

     <<  WebViewController.new.tap  do  |c|      c.url  =  'http://example.com'   end  
  25. 3VCZ.PUJPOͱSVCZHFNT •  ௨ৗͷHFN͸࢖͑ͳ͍ –  ίʔυ಺Ͱ͸SFRVJSF͕࢖͑ͳ͍ •  3VCZ.PUJPO༻HFN͕࢖͑Δ –  3BLFpMF಺ͰSFRVJSF͢Δ

  26. ୅දతͳ΋ͷ •  #VCCMF8SBQ •  4VHBSDVCF •  NPUJPOTVQQPSU •  /BOP4UPSF*O.PUJPO • 

    (FPNPUJPO •  'PSNPUJPO •  ŋŋŋ
  27. #VCCMF8SBQ #  Asynchronous  HTTP   BW::HTTP.get("https://api.github.com/users/mattetti")  do  |response|    

     p  response.body.to_str   end   #  Timer   timer  =  EM.add_periodic_timer  1.0  do      count  =  count  +  1      (count  <  10)  ||  EM.cancel_timer(timer)   end   #  Observers   include  BW::KVO   observe(@label,  :text)  do  |old_value,  new_value|      ...   end  
  28. 4VHBSDVCF #  navigationController.pushViewController(c,  animated:true)   navigationController  <<  c   #

     self.view.addSubView(@label)   self.view  <<  @label   #  UIButton.buttonWithType(UIButtonTypeRoundedRect)   UIButton.rounded_rect   #  button.addTarget(self,  action:'ButtonDidPush',  forControlEvents:UIControlEventTouchUpInside)   button.on(:touch)  do      ...   end  
  29. NPUJPOTVQQPSU #  motion-­‐support/core_ext/time   1.weeks.ago   17.days.from_now   #  motion-­‐support/inflector

      "app_delegate".camelize   "thing".pluralize   #  motion-­‐support/core_ext/object   nil.blank?   1.try(:to_s)  
  30. /BOP4UPSF*O.PUJPO class  User  <  NanoStore::Model      attribute  :name  

       attribute  :age      attribute  :created_at      bag  :cars   end     user  =  User.new(:name  =>  "Bob",  :age  =>  16,  :created_at  =>  Time.now)   user.save   users  =  User.find(:name  =>  {  NSFEqualTo  =>  "Ronald"  })        
  31. SVCZNPUJPOXSBQQFSTDPN

  32. 3VCZ.PUJPOͱ0CK$ϥΠϒϥϦ •  ී௨ʹϦϯΫͰ͖Δ

  33. NPUJPODPDPBQPET •  $PDPBQPETͷϥΠϒϥϦΛ3VCZ.PUJPOͰ #  Rakefile   Motion::Project::App.setup  do  |app|  

       app.name  =  'HBFav2'      app.pods  do          pod  'SSPullToRefresh'  #  Cocoapods      end   end   #  in  ViewController   @ptrv  =  SSPullToRefreshView.alloc.initWithScrollView(...)  
  34. None
  35. 5*14

  36. 3VCZ.PUJPOͱϏϧυγεςϜ •  ίϯύΠϥपΓ͸ϓϩϓϥΠΤλϦ •  ϏϧυγεςϜपΓ͸044ɺ׌ͭ3VCZ –  HFN͕৭ʑ͋Δͷ͸ͦͷࣀ –  &BTZUP)BDL

  37. %BTI

  38. #VOEMFS •  SVCZHFNTͷΠϯετʔϧʹ͸#VOEMFS࢖͑Δ %  emacs  Gemfile   %  bundle  -­‐-­‐path=vendor/bundle

      %  bundle  exec  rake  
  39. σόοά •  HEC͕࢖͑·͢ $  rake  debug=1  no_continue=1   [...]  

    (gdb)  break  hello_view.rb:10   Breakpoint  4  (hello_view.rb:10)  pending.   (gdb)  continue   Continuing.  
  40. ओʹ QSJOUσόοά͚ͩͲͳ

  41. ςετ •  3TQFDͰॻ͚Δ͠ɺ͍Ζ͍Ζ͋Δ

  42. ςετ ॻ͍ͯͳ͍͚Ͳͳ

  43. 5SBWJT$*

  44. $*͢Δςετ ͳ͍͚Ͳͳ

  45. ·ͱΊ •  3VCZ.PUJPO͸0CKFDUJWF$3VOUJNFͰ࣮૷͞Εͨ 3VCZ •  σϕϩούʔϑϨϯυϦʔͳπʔϧͰ։ൃͰ͖·͢ •  ϥΠϒϥϦͰ3VCZΒ͘͠ •  0CKFDUJWF$ͷࢿ࢈͕ͦͷ··࢖͑·͢