{"id":4455,"url":"https://github.com/dsibiski/react-native-userdefaults-ios","last_synced_at":"2025-12-15T01:58:40.937Z","repository":{"id":32128226,"uuid":"35700827","full_name":"dsibiski/react-native-userdefaults-ios","owner":"dsibiski","description":"React Native Module for NSUserDefaults","archived":false,"fork":false,"pushed_at":"2019-11-04T11:44:26.000Z","size":29,"stargazers_count":71,"open_issues_count":8,"forks_count":27,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-11T14:08:29.959Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-native-userdefaults-ios","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dsibiski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-15T22:56:38.000Z","updated_at":"2024-08-19T22:44:38.000Z","dependencies_parsed_at":"2022-09-11T19:23:46.663Z","dependency_job_id":null,"html_url":"https://github.com/dsibiski/react-native-userdefaults-ios","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsibiski%2Freact-native-userdefaults-ios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsibiski%2Freact-native-userdefaults-ios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsibiski%2Freact-native-userdefaults-ios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsibiski%2Freact-native-userdefaults-ios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dsibiski","download_url":"https://codeload.github.com/dsibiski/react-native-userdefaults-ios/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228582487,"owners_count":17940587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:17:13.118Z","updated_at":"2025-12-15T01:58:40.900Z","avatar_url":"https://github.com/dsibiski.png","language":"Objective-C","funding_links":[],"categories":["Components"],"sub_categories":["Utils \u0026 Infra"],"readme":"## react-native-userdefaults-ios [![Build Status](https://travis-ci.org/dsibiski/react-native-userdefaults-ios.svg?branch=master)](https://travis-ci.org/dsibiski/react-native-userdefaults-ios)\nReact Native Module for [NSUserDefaults](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/)\n\nThis 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.\n\n[![NPM](https://nodei.co/npm/react-native-userdefaults-ios.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/react-native-userdefaults-ios/)\n\n### Add it to your project\n\n1. Run `npm install react-native-userdefaults-ios --save`\n2. Open your project in XCode, right click on `Libraries` and click `Add\n   Files to \"Your Project Name\"`.\n3. Select the `RNUserDefaultsIOS.xcodeproj` file in the `node_modules/react-native-userdefaults-ios` folder and click `Add`\n4. In the Xcode Project Navigator, select your project and add `libRNUserDefaultsIOS.a` from the `Libraries/RNUserDefaultsIOS.xcodeproj/Products` folder to `Build Phases -\u003e Link Binary With Libraries`.\n5. Follow the implementation example below...\n\n### Example\n\n```javascript\n// Require the library...\nvar UserDefaults = require('react-native-userdefaults-ios');\n```\n\n#### Writing to `standardUserDefaults`\n```javascript\n//Set an Array...\nvar arr = ['1', '2', '3'];\nUserDefaults.setArrayForKey(arr, 'keyForMyArray')\n    .then(result =\u003e {\n        console.log(result);\n    });\n\n// Set a String...\nUserDefaults.setStringForKey('myString', 'keyForMyString')\n    .then(result =\u003e {\n        console.log(result);\n    });\n\n//Set an Object...\nvar obj = {\n    name: 'Dave'\n};\nUserDefaults.setObjectForKey(obj, 'keyForMyObject')\n    .then(result =\u003e {\n        console.log(result);\n    });\n\n//Set a boolean value...\nUserDefaults.setBoolForKey(true, 'keyForMyBool')\n    .then(result =\u003e {\n        console.log(result);\n    });\n\n//Remove an item (works for any type)...\nUserDefaults.removeItemForKey('keyOfItemToRemove')\n    .then(result =\u003e {\n        console.log(result);\n    });\n```\n\n#### Reading from `standardUserDefaults`\n```javascript\n// Get an array for a given key...\nUserDefaults.arrayForKey('keyForMyArray')\n    .then(array =\u003e {\n        //Do something with the returned array...\n        array.forEach(item =\u003e {\n            console.log(item);\n        });\n    });\n\n// Get a string for a given key...\nUserDefaults.stringForKey('keyForMyString')\n    .then(string =\u003e {\n        //Do something with the returned string...\n        console.log(string);\n    });\n\n// Get an object for a given key...\nUserDefaults.objectForKey('keyForMyObject')\n    .then(obj =\u003e {\n        //Do something with the returned object...\n        console.log(obj);\n    });\n\n// Get a boolean value for a given key...\nUserDefaults.boolForKey('keyForMyBool')\n    .then(bool =\u003e {\n        //Do something with the returned boolean value...\n        console.log(bool);\n    });\n```\n\n### Todos for 1.0 release\n\n- [ ] Implement `dataForKey:`\n- [ ] Implement `stringArrayForKey:`\n- [ ] Implement `setFloat:forKey:`\n- [ ] Implement `floatForKey:`\n- [ ] Implement `setInteger:forKey:`\n- [ ] Implement `integerForKey:`\n- [ ] Implement `setDouble:forKey:`\n- [ ] Implement `doubleForKey:`\n- [ ] Implement `setURL:forKey:`\n- [ ] Implement `URLForKey:`\n- [ ] Implement `NSUserDefaultsDidChangeNotification`\n\n### Todos for 0.1.0 release - DONE!\n\n- [x] Implement `arrayForKey:`\n- [x] Implement `stringForKey:`\n- [x] Implement `setObject:forKey:`\n- [x] Implement `objectForKey:`\n- [x] Implement `removeObjectForKey:`\n- [x] Implement `dictionaryForKey:` Note: This was taken care of with `objectForKey` since in JS an Object is a Dictionary in Obj-C\n- [x] Implement `setBool:forKey:`\n- [x] Implement `boolForKey:`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsibiski%2Freact-native-userdefaults-ios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdsibiski%2Freact-native-userdefaults-ios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsibiski%2Freact-native-userdefaults-ios/lists"}