Code Monkey home page Code Monkey logo

binary_plist's Introduction

BinaryPlist

Rails plugin for easily adding a binary plist format. The binary plist format is ideal for transferring data to an Objective-C based application.

Note: This is still a work in progress. It should be ready to use for most applications. The most noticeable issue is the lack of support for large integers.

Installation

Add the following line to your bundle and run bundle install.

gem "binary_plist"

Usage

All you have to do is add the plist format to your respond_to block:

def index
  @posts = Post.all
  respond_to do |format|
    format.html
    format.plist { render :plist => @posts }
  end
end

You can do the combined style if you're support multiple formats like json or xml.

def index
  @posts = Post.all
  respond_to do |format|
    format.html
    format.any(:json, :plist) { render request.format.to_sym => @posts }
  end
end

Consuming

On the Objective-C side, it's ridiculously easy to consume the plist data.

NSURL *url = [NSURL URLWithString:@"http://localhost:3000/posts.plist"];
NSArray *posts = [NSArray arrayWithContentsOfURL:url];

You can also use the more flexible syntax:

NSURL *url = [NSURL URLWithString:@"http://localhost:3000/posts.plist"];
NSDate *date = [NSData dataWithContentsOfURL:url];
id result = [NSPropertyListSerialization propertyListFromData:data 
             mutabilityOption:NSPropertyListImmutable format:NULL errorDescription:nil];

if ([result isKindOfClass:[NSArray class]]) {
  // Handle array response
} else if ([result isKindOfClass:[NSDictionary class]]) {
  // Handle dictionary response
} else {
  // Etc...
}

Thanks

The encoder is largely based on Apple Binary Property List serializer.

Copyright (c) 2010-2011 Sam Soffes, released under the MIT license

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.