Upload
masakuni-kato
View
3.332
Download
4
Embed Size (px)
Citation preview
RubyMotion で iOS 開発
2013/04/27 【豊橋】第1回 iPhoneアプリ開発勉強会 加藤匡邦 (エアーズ株式会社)
自己紹介
@mackato
Mr. kato (bruce lee) in Green Hornet.
from Hamamatsu!
Original Update by hirotomo
エアーズ株式会社
毎日つかえるアプリを作る
Hi-Cube
浜松本社
Tokyo office in TSUKIJI※写真はイメージです
Original Update by graney
ウェブ開発Ruby on Rails
おいしいはiPhoneが覚えてる
お財布はスリムに、お店はスマートに
WWDC 2012 attendee
WWDC 2013 sells out in 2 minutes!
Hamamatsu.rb #1Hamamatsu.rb 2011.03.09~
Hamackathon
Hamackathon#2 Mobile - 2010.12.04
Hamackathon
JAWS-UG 浜松
http://jaws-ug.jp/bc/hamamatsu/
Ruby
Rubyオブジェクト指向
シンプルな文法
動的な型付け
Web開発
サーバー管理
パッケージ管理
RubyMotion
RubyMotionRubyで書ける
iOSネイティブ
iOSライブラリが使える
$199.99有料です
¥20,513アベノミクス
2013/4/27現在
Write with Rubyclass AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) @window.makeKeyAndVisible
@blue_view = UIView.alloc.initWithFrame(CGRectMake(10, 10, 100, 100)) @blue_view.backgroundColor = UIColor.blueColor @window.addSubview(@blue_view)
true endend
app_delegate.rb
Use Power of Rubyclass AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) @window.makeKeyAndVisible %w(blue-lagoon red-ocean black-coffee).each_with_index do |str, i| UIView.alloc.init.tap do |view| view.frame = [[50 * i, 50 * i + 20], [100, 100]] view.backgroundColor = UIColor.send(:"#{$1}Color") @window.addSubview(view) end if str =~ /^(?!black)(\w+)\-.+/ end true endend
app_delegate.rb
Metaprogramming
http://clayallsopp.com/posts/rubymotion-metaprogramming/
def tableView(tableView,
didSelectRowAtIndexPath:indexPath)
menu_row = self.menu_items[indexPath.row]
# => 'profile'
self.send("open_#{menu_row}")
end
def open_profile; #...; end
def open_messages; #...; end
def open_feed; # ...; end
class Profile
# EX: has_one :user
def self.has_one(name)
klass = make_klass_from_name(name)
# EX: => User
# Effect: (a_profile.user = a_user)
# === a_user.profile_id = 4
define_method("#{name}=") do |value|
value.send("#{self.class.stringify}_id=", self.id)
value.save
value
end
end
def self.stringify; "profile"; end
end
send define_method
Hello Motion% motion create HelloMotion Create HelloMotion Create HelloMotion/.gitignore Create HelloMotion/Rakefile Create HelloMotion/app Create HelloMotion/app/app_delegate.rb Create HelloMotion/resources Create HelloMotion/resources/[email protected] Create HelloMotion/spec Create HelloMotion/spec/main_spec.rb
Goodbye XcodeHelloMotion/"## Rakefile"## app$ %## app_delegate.rb"## resources$ %## [email protected]%## spec %## main_spec.rb
GoodbyeXcode/"## GoodbyeXcode$ "## [email protected]$ "## Default.png$ "## [email protected]$ "## GXAppDelegate.h$ "## GXAppDelegate.m$ "## GoodbyeXcode-Info.plist$ "## GoodbyeXcode-Prefix.pch$ "## en.lproj$ $ %## InfoPlist.strings$ %## main.m"## GoodbyeXcode.xcodeproj$ "## project.pbxproj$ "## project.xcworkspace$ $ "## contents.xcworkspacedata$ $ %## xcuserdata$ $ %## kato.xcuserdatad$ $ %## UserInterfaceState.xcuserstate$ %## xcuserdata$ %## kato.xcuserdatad$ %## xcschemes$ "## GoodbyeXcode.xcscheme$ %## xcschememanagement.plist%## GoodbyeXcodeTests "## GoodbyeXcodeTests-Info.plist "## GoodbyeXcodeTests.h "## GoodbyeXcodeTests.m %## en.lproj %## InfoPlist.strings
Run Application% rake Build ./build/iPhoneSimulator-6.1-Development Compile ./app/app_delegate.rb Create ./build/iPhoneSimulator-6.1-Development/HelloMotion.app Link ./build/iPhoneSimulator-6.1-Development/HelloMotion.app/HelloMotion Create ./build/iPhoneSimulator-6.1-Development/HelloMotion.app/Info.plist Create ./build/iPhoneSimulator-6.1-Development/HelloMotion.app/PkgInfo Copy ./resources/[email protected] Create ./build/iPhoneSimulator-6.1-Development/HelloMotion.dSYMwarning: no debug symbols in executable (-arch i386) Simulate ./build/iPhoneSimulator-6.1-Development/HelloMotion.app(main)>
REPL - interactive console% rake Build ./build/iPhoneSimulator-6.1-Development Compile ./app/app_delegate.rb Link ./build/iPhoneSimulator-6.1-Development/HelloMotion.app/HelloMotion Create ./build/iPhoneSimulator-6.1-Development/HelloMotion.app/Info.plist Create ./build/iPhoneSimulator-6.1-Development/HelloMotion.app/PkgInfo Create ./build/iPhoneSimulator-6.1-Development/HelloMotion.dSYM Simulate ./build/iPhoneSimulator-6.1-Development/HelloMotion.app(main)> 2013-04-27 15:31:48.161 HelloMotion[1990:c07] Application windows ...(main)> self=> main(#<UIView:0x7648df0>)> self.backgroundColor = UIColor.whiteColor=> #<UICachedDeviceWhiteColor:0xa96f180>(#<UIView:0x7648df0>)>
motion-cocoapods
Rakefile
# -‐*-‐ coding: utf-‐8 -‐*-‐$:.unshift("/Library/RubyMotion/lib")require 'motion/project'require 'rubygems'require 'motion-‐cocoapods' Motion::Project::App.setup do |app| # Use `rake config' to see complete project settings. app.name = 'HelloMotion' app.pods do pod 'JSONKit' endend
Bundler
Rakefile
# -‐*-‐ coding: utf-‐8 -‐*-‐$:.unshift("/Library/RubyMotion/lib")require 'motion/project'require 'bundler'Bundler.require Motion::Project::App.setup do |app| # Use `rake config' to see complete project settings. app.name = 'HelloMotion' app.pods do pod 'JSONKit' endend
Gemfile
source 'https://rubygems.org' gem 'rake'gem 'motion-‐cocoapods'gem 'bubble-‐wrap'gem 'sugarcube'
BubbleWrap# Uses the front cameraBW::Device.camera.front.picture(media_types: [:movie, :image]) do |result| image_view = UIImageView.alloc.initWithImage(result[:original_image])end
Camera
BW::Location.get do |result| p "From Lat #{result[:from].latitude}, Long #{result[:from].longitude}" p "To Lat #{result[:to].latitude}, Long #{result[:to].longitude}"end
Location
BW::HTTP.get("https://api.github.com/users/mattetti") do |response| p response.body.to_strend
HTTP
Sugarcube0xffffff.uicolor # => UIColor.colorWithRed(1.0, green:1.0, blue:1.0, alpha:1.0)
5.days.ago # => 2012-‐12-‐29 11:42:24 -‐0700
Fixnum
# UIApplication.sharedApplication.openURL(NSURL.URLWithString("https://github.com"))"https://github.com".nsurl.open
NSURL
# UIImage from name"my_image".uiimage # => UIImage.imageNamed("my_image")
# UIFont from name"my_font".uifont(20) # => UIFont.fontWithName("my_font", size:20)
# NSLocalizedString from string"hello".localized # => NSBundle.mainBundle.localizedStringForKey("hello", value:nil, table:nil)"hello"._ # == "hello".localized
NSString
In the real world
EverClipWinner of Evernote DevCup 2012!
Basecamp37signals product
http://www.rubymotion.com/apps/
Community
RubyMotionもくもく会次回 2013/05/22
RubyMotion Kaigi 20132013/05/29
Books
RubyMotion RubyMotion入門@clayallsopp @naoya_ito
See alsoRubyMotion Developer Centerhttp://www.rubymotion.com/developer-center/
RubyMotion JPhttp://rubymotion.jp/
RubyMotion Wrappershttp://rubymotion-wrappers.com/
ConclusionRubyが書けてiOS未経験の方にはお薦め
RubyMotion以外にRuby使わない人には??
xcodeprojが無いので共同作業はしやすい
Thanks!2013/05/8 19:00~ Hamamatsu.rb#27
参加者募集中!
http://atnd.org/events/38863