Rapture In Venice, LLC – John Blanco

:: Freelance iOS and Xamarin Development

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:


# -*- coding: utf-8 -*-
require 'motion/project'

Motion::Project::App.setup do |app|
  app.name = 'ExEmEl'
  app.libs << '/usr/lib/libxml2.dylib'
  app.vendor_project "vendor/RaptureXML", :xcode


Source Code

    xml = <<-eos
          <student name="Jane">80</student>
          <student name="John">95</student>
          <student name="Joe">60</student>

    # 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!

  • Print
  • Facebook
  • Twitter

John Blanco

John Blanco is a freelance iOS and Xamarin developer living in Lakewood, CO. He's been developing mobile apps for 10 years, beginning in the medieval days of Java ME and Blackberry, making him the ultimate hipster mobile engineer. Follow him on Twitter!

More Posts

Follow Me:

, ,

Comments are currently closed.