Using RaptureXML in RubyMotion
One of the cooler features of RubyMotion is that you can bring in your favorite 3rd-party Objective-C code. Without this ability, you wouldn’t be able to use essential libraries such as Cocos2D, Sparrow and SDWebImage. Could you imagine?
Although the process RubyMotion requires to bring this code in is easier than you’d expect, it can be tricky and sometimes technical. That being said, if you’re looking to use RaptureXML in ruby form, here’s a sample Rakefile and usage. First, you need to copy the entire RaptureXML source directory into your app’s vendor/ directory. Then, use the following:
Rakefile
# -*- coding: utf-8 -*- $:.unshift("/Library/RubyMotion/lib") require 'motion/project' Motion::Project::App.setup do |app| app.name = 'ExEmEl' app.libs << '/usr/lib/libxml2.dylib' app.vendor_project "vendor/RaptureXML", :xcode end
Source Code
xml = <<-eos <scores> <student name="Jane">80</student> <student name="John">95</student> <student name="Joe">60</student> </scores> eos # load xml rxml = RXMLElement.elementFromXMLString(xml, encoding:NSUTF8StringEncoding) # calculate average test score total_score = num_scores = 0 rxml.iterate("student", usingBlock:lambda { |e| total_score += e.textAsInt num_scores += 1 }) NSLog("Average score: #{total_score / num_scores}")
After updating the vendor code specification, I like to run a rake clean
because sometimes RubyMotion doesn’t pick up the code correctly if you don’t. If you did everything right, you now have the power of RaptureXML in RubyMotion!
What’s the point of your library if you won’t tell me how to use it? How to Link to your App in the App Store (WHY WAS THIS SO HARD?!)
Comments are currently closed.