Giter Club home page Giter Club logo

plistreadwrite's Introduction

PListReadWrite

A Rubymotion module to make light work of writing to and reading from plist files.

Installation

Add the following to your app's Gemfile

gem 'plist_read_write'

Alternatively, it's a small file so you can just copy/paste it directly to your app.

Example Usage

Lets assume we have this plist file in our resources directory...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>jim</key>
    <dict>
      <key>name</key>
      <string>Jim</string>
      <key>email</key>
      <string>[email protected]</string>
    </dict>
    <key>jane</key>
    <dict>
      <key>name</key>
      <string>Jane</string>
      <key>email</key>
      <string>[email protected]</string>
    </dict>
  </dict>
</plist>

... and we want to copy it over to our app's documents directory so we can update/edit the plist.

# Check if the plist exists in our documents dir
PListRW.exist?(:users, :documentsDir) # => false

# Check if the plist exists in our main bundle
PListRW.exist?(:users, :mainBundle) # => true

# Copy the plist file from the main bundle to the documents dir
PListRW.copyPlistFileFromBundle(:users)

# Fetch the object from the plist file
@users_hash = PListRW.plistObject(:users, Hash) # => A hash containing the User data

# Update the data
@users_hash[:jim] # => { name: "Jim", email: "[email protected]" }
@users_hash[:jim][:name] = 'James'

# Store the data back in the plist
PListRW.updatePlistFileWithObject(:users, @users_hash)

# Check this worked OK
PListRW.plistObject(:users, Hash)[:jim][:name] # => "James"

About Katana Code

Katana Code are iPhone app and Ruby on Rails Developers in Edinburgh, Scotland.

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.