npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-userdefaults-ios

v0.1.3

Published

React Native Module for NSUserDefaults

Downloads

193

Readme

react-native-userdefaults-ios Build Status

React Native Module for NSUserDefaults

This library is especially helpful for hybrid apps that already make use of [NSUserDefaults standardUserDefaults] and would like to read or write to it from within their React components.

NPM

Add it to your project

  1. Run npm install react-native-userdefaults-ios --save
  2. Open your project in XCode, right click on Libraries and click Add Files to "Your Project Name".
  3. Select the RNUserDefaults.xcodeproj file in the node_modules/react-native-userdefaults-ios folder and click Add
  4. In the Xcode Project Navigator find the RNUserDefaults.xcodproj and add the Products/libRNUserDefaultsIOS.a to Build Phases -> Link Binary With Libraries.
  5. Follow the implementation example below...

Example

// Require the library...
var UserDefaults = require('react-native-userdefaults-ios');

Writing to standardUserDefaults

//Set an Array...
var arr = ['1', '2', '3'];
UserDefaults.setArrayForKey(arr, 'keyForMyArray')
    .then(result => {
        console.log(result);
    });

// Set a String...
UserDefaults.setStringForKey('myString', 'keyForMyString')
    .then(result => {
        console.log(result);
    });

//Set an Object...
var obj = {
    name: 'Dave'
};
UserDefaults.setObjectForKey(obj, 'keyForMyObject')
    .then(result => {
        console.log(result);
    });

//Set a boolean value...
UserDefaults.setBoolForKey(true, 'keyForMyBool')
    .then(result => {
        console.log(result);
    });

//Remove an item (works for any type)...
UserDefaults.removeItemForKey('keyOfItemToRemove')
    .then(result => {
        console.log(result);
    });

Reading from standardUserDefaults

// Get an array for a given key...
UserDefaults.arrayForKey('keyForMyArray')
    .then(array => {
        //Do something with the returned array...
        array.forEach(item => {
            console.log(item);
        });
    });

// Get a string for a given key...
UserDefaults.stringForKey('keyForMyString')
    .then(string => {
        //Do something with the returned string...
        console.log(string);
    });

// Get an object for a given key...
UserDefaults.objectForKey('keyForMyObject')
    .then(obj => {
        //Do something with the returned object...
        console.log(obj);
    });

// Get a boolean value for a given key...
UserDefaults.boolForKey('keyForMyBool')
    .then(bool => {
        //Do something with the returned boolean value...
        console.log(bool);
    });

Todos for 1.0 release

  • [ ] Implement dataForKey:
  • [ ] Implement stringArrayForKey:
  • [ ] Implement setFloat:forKey:
  • [ ] Implement floatForKey:
  • [ ] Implement setInteger:forKey:
  • [ ] Implement integerForKey:
  • [ ] Implement setDouble:forKey:
  • [ ] Implement doubleForKey:
  • [ ] Implement setURL:forKey:
  • [ ] Implement URLForKey:
  • [ ] Implement NSUserDefaultsDidChangeNotification

Todos for 0.1.0 release - DONE!

  • [x] Implement arrayForKey:
  • [x] Implement stringForKey:
  • [x] Implement setObject:forKey:
  • [x] Implement objectForKey:
  • [x] Implement removeObjectForKey:
  • [x] Implement dictionaryForKey: Note: This was taken care of with objectForKey since in JS an Object is a Dictionary in Obj-C
  • [x] Implement setBool:forKey:
  • [x] Implement boolForKey: