{"id":4458,"url":"https://github.com/wwayne/react-native-user-defaults","last_synced_at":"2025-04-23T13:31:53.353Z","repository":{"id":79177583,"uuid":"47924854","full_name":"wwayne/react-native-user-defaults","owner":"wwayne","description":"All you need is set and get","archived":false,"fork":false,"pushed_at":"2016-11-08T13:53:40.000Z","size":15,"stargazers_count":58,"open_issues_count":3,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-30T06:42:47.868Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wwayne.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-12-13T15:32:28.000Z","updated_at":"2024-04-19T01:59:08.000Z","dependencies_parsed_at":"2024-01-27T01:21:27.883Z","dependency_job_id":"f0cec3a8-6a06-4624-bb2e-a49c2148e4cb","html_url":"https://github.com/wwayne/react-native-user-defaults","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwayne%2Freact-native-user-defaults","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwayne%2Freact-native-user-defaults/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwayne%2Freact-native-user-defaults/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wwayne%2Freact-native-user-defaults/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wwayne","download_url":"https://codeload.github.com/wwayne/react-native-user-defaults/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223926213,"owners_count":17226412,"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.201Z","updated_at":"2024-11-10T07:32:36.816Z","avatar_url":"https://github.com/wwayne.png","language":"Objective-C","readme":"# react-native-user-defaults\n[![Version](http://img.shields.io/npm/v/react-native-user-defaults.svg)](https://www.npmjs.org/package/react-native-user-defaults)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)\n[![Circle CI](https://circleci.com/gh/wwayne/react-native-user-defaults/tree/master.svg?style=svg)](https://circleci.com/gh/wwayne/react-native-user-defaults/tree/master)\n\n## When to use UserDefaults\nwhen you want to store some small ,insensitive and permanent information in your app\n\n## Installation\n\n1. `npm install react-native-user-defaults`\n2. open xcode, right click on `Libraries`, then click `Add Files...`, select `node_modules -\u003e react-native-user-defaults -\u003e RCTUserDefaults.xcodeproj`\n3. still in xcode, select main project file, then `Build Phases -\u003e Link Binary... -\u003e Add items -\u003e libRCTUserDefaults.a`\n\nIf you are not clear about the step 2 and 3, you can check react-native [official doc](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content) , follow the step 1 and 2 in the official doc.\n\n## Usage\nIn **objective-c** and **swift**, you have to use specific method for specific type, like `setObject` and `stringForKey`. But in **react-native**, I believe that all you need is just `set` and `get`.\n\nEvery method supports `callback` and `promise`\n\n```\nimport userDefaults from 'react-native-user-defaults'\n```\n#### Set information for a key\n\n```\nset({String}, {String, Number, Bool, Object, Array}, [,suiteName] [,callback])\n\nExample:\nuserDefaults.set(\"key1\", \"valueIsString\")\n .then(data =\u003e console.log(data))   // Save success\n\nuserDefaults.set(\"key2\", [1, true], \"group.com.company.app\", (err, data) =\u003e {\n if(!err) console.log(data)         // Save success\n})\n```\n\n#### Get information of a key\n\n```\nget({String} [,suiteName] [,callback])\n\nExample:\nuserDefaults.get(\"key1\")\n .then(data =\u003e console.log(data))   // value for the key1\n\nuserDefaults.get(\"key2\", \"group.com.company.app\", (err, data) =\u003e {\n if(!err) console.log(data)         // value for the key2\n})\n```\n\n#### Remove an item\n\n```\nremove({String} [,suiteName] [,callback])\n\nExample:\nuserDefaults.remove(\"key1\")\n .then(data =\u003e console.log(data))   // Remove success\n```\n\n#### Empty all items which are not default(APP default settings will be reserved)\n\n```\nempty([suiteName] [,callback])\n\nExample:\nuserDefaults.empty()\n .then(data =\u003e console.log(data))   // Empty success\n```\n\n## Troubleshooting\n\n1. No tests? I have tested all methods, I promise. I've checked other famous react-native components, they all don't have tests, I think we are all seeking a way of formal tests.\n2. Why not swift? I wrote this in swift at the beginning, but I find it's hard for others and even myself to integrate it into an existed project.\n3. Type bug? if you `set('key1', '12')`, then `get('key1')`, you will get `12`, not `'12'`, I don't take this as a bug so that we can use this component more conveniently. If you don't think so, tell me.\n\n## License\nMIT\n","funding_links":[],"categories":["Components"],"sub_categories":["Utils \u0026 Infra"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwwayne%2Freact-native-user-defaults","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwwayne%2Freact-native-user-defaults","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwwayne%2Freact-native-user-defaults/lists"}