├── .gitignore ├── .jshintrc ├── .travis.yml ├── Podfile ├── Podfile.lock ├── README.md ├── RNUserDefaultsIOS.js ├── RNUserDefaultsIOS.xcodeproj ├── project.pbxproj └── xcshareddata │ └── xcschemes │ └── RNUserDefaultsIOS.xcscheme ├── RNUserDefaultsIOS.xcworkspace └── contents.xcworkspacedata ├── RNUserDefaultsIOS ├── RNUserDefaultsIOS.h ├── RNUserDefaultsIOS.m ├── UserDefaultsManager.h └── UserDefaultsManager.m ├── RNUserDefaultsIOSTests ├── Info.plist └── UserDefaultsManagerSpec.m └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # xcode noise 2 | build/* 3 | *.pbxuser 4 | *.mode1v3 5 | *.mode2v3 6 | *.perspectivev3 7 | *.xcuserstate 8 | *.xccheckout 9 | project.xcworkspace/ 10 | xcuserdata/ 11 | 12 | # old skool 13 | .svn 14 | 15 | # osx noise 16 | .DS_Store 17 | profile 18 | 19 | # node.js 20 | # 21 | npm-debug.log 22 | node_modules/ 23 | 24 | # CocoaPods 25 | Pods/ 26 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "camelcase" : true, 3 | "indent": 4, 4 | "undef": true, 5 | "quotmark": "single", 6 | "maxlen": 80, 7 | "trailing": true, 8 | "curly": true, 9 | "node": true, 10 | "jasmine": true, 11 | "esnext": true 12 | } 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | 3 | cache: 4 | directories: 5 | - node_modules 6 | - Pods 7 | 8 | install: 9 | - npm install 10 | - npm install react-native 11 | - pod install 12 | 13 | xcode_workspace: RNUserDefaultsIOS.xcworkspace 14 | xcode_scheme: RNUserDefaultsIOS 15 | xcode_sdk: iphonesimulator8.1 16 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | target 'RNUserDefaultsIOSTests' do 2 | pod 'Specta' 3 | pod 'Expecta' 4 | pod 'OCMockito' 5 | end 6 | 7 | -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Expecta (1.0.0) 3 | - OCHamcrest (4.1.1) 4 | - OCMockito (1.4.0): 5 | - OCHamcrest (~> 4.0) 6 | - Specta (1.0.0) 7 | 8 | DEPENDENCIES: 9 | - Expecta 10 | - OCMockito 11 | - Specta 12 | 13 | SPEC CHECKSUMS: 14 | Expecta: 32604574add2c46a36f8d2f716b6c5736eb75024 15 | OCHamcrest: 6f03ffa81d12feab872638490a44ab0a6d3aca10 16 | OCMockito: 4981140c9a9ec06c31af40f636e3c0f25f27e6b2 17 | Specta: 96fe05fe5c7348b5223f85e862904f6e832abb14 18 | 19 | COCOAPODS: 0.37.0 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 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) 2 | React Native Module for [NSUserDefaults](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/) 3 | 4 | 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. 5 | 6 | [![NPM](https://nodei.co/npm/react-native-userdefaults-ios.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/react-native-userdefaults-ios/) 7 | 8 | ### Add it to your project 9 | 10 | 1. Run `npm install react-native-userdefaults-ios --save` 11 | 2. Open your project in XCode, right click on `Libraries` and click `Add 12 | Files to "Your Project Name"`. 13 | 3. Select the `RNUserDefaultsIOS.xcodeproj` file in the `node_modules/react-native-userdefaults-ios` folder and click `Add` 14 | 4. In the Xcode Project Navigator, select your project and add `libRNUserDefaultsIOS.a` from the `Libraries/RNUserDefaultsIOS.xcodeproj/Products` folder to `Build Phases -> Link Binary With Libraries`. 15 | 5. Follow the implementation example below... 16 | 17 | ### Example 18 | 19 | ```javascript 20 | // Require the library... 21 | var UserDefaults = require('react-native-userdefaults-ios'); 22 | ``` 23 | 24 | #### Writing to `standardUserDefaults` 25 | ```javascript 26 | //Set an Array... 27 | var arr = ['1', '2', '3']; 28 | UserDefaults.setArrayForKey(arr, 'keyForMyArray') 29 | .then(result => { 30 | console.log(result); 31 | }); 32 | 33 | // Set a String... 34 | UserDefaults.setStringForKey('myString', 'keyForMyString') 35 | .then(result => { 36 | console.log(result); 37 | }); 38 | 39 | //Set an Object... 40 | var obj = { 41 | name: 'Dave' 42 | }; 43 | UserDefaults.setObjectForKey(obj, 'keyForMyObject') 44 | .then(result => { 45 | console.log(result); 46 | }); 47 | 48 | //Set a boolean value... 49 | UserDefaults.setBoolForKey(true, 'keyForMyBool') 50 | .then(result => { 51 | console.log(result); 52 | }); 53 | 54 | //Remove an item (works for any type)... 55 | UserDefaults.removeItemForKey('keyOfItemToRemove') 56 | .then(result => { 57 | console.log(result); 58 | }); 59 | ``` 60 | 61 | #### Reading from `standardUserDefaults` 62 | ```javascript 63 | // Get an array for a given key... 64 | UserDefaults.arrayForKey('keyForMyArray') 65 | .then(array => { 66 | //Do something with the returned array... 67 | array.forEach(item => { 68 | console.log(item); 69 | }); 70 | }); 71 | 72 | // Get a string for a given key... 73 | UserDefaults.stringForKey('keyForMyString') 74 | .then(string => { 75 | //Do something with the returned string... 76 | console.log(string); 77 | }); 78 | 79 | // Get an object for a given key... 80 | UserDefaults.objectForKey('keyForMyObject') 81 | .then(obj => { 82 | //Do something with the returned object... 83 | console.log(obj); 84 | }); 85 | 86 | // Get a boolean value for a given key... 87 | UserDefaults.boolForKey('keyForMyBool') 88 | .then(bool => { 89 | //Do something with the returned boolean value... 90 | console.log(bool); 91 | }); 92 | ``` 93 | 94 | ### Todos for 1.0 release 95 | 96 | - [ ] Implement `dataForKey:` 97 | - [ ] Implement `stringArrayForKey:` 98 | - [ ] Implement `setFloat:forKey:` 99 | - [ ] Implement `floatForKey:` 100 | - [ ] Implement `setInteger:forKey:` 101 | - [ ] Implement `integerForKey:` 102 | - [ ] Implement `setDouble:forKey:` 103 | - [ ] Implement `doubleForKey:` 104 | - [ ] Implement `setURL:forKey:` 105 | - [ ] Implement `URLForKey:` 106 | - [ ] Implement `NSUserDefaultsDidChangeNotification` 107 | 108 | ### Todos for 0.1.0 release - DONE! 109 | 110 | - [x] Implement `arrayForKey:` 111 | - [x] Implement `stringForKey:` 112 | - [x] Implement `setObject:forKey:` 113 | - [x] Implement `objectForKey:` 114 | - [x] Implement `removeObjectForKey:` 115 | - [x] Implement `dictionaryForKey:` Note: This was taken care of with `objectForKey` since in JS an Object is a Dictionary in Obj-C 116 | - [x] Implement `setBool:forKey:` 117 | - [x] Implement `boolForKey:` 118 | -------------------------------------------------------------------------------- /RNUserDefaultsIOS.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var { NativeModules } = require('react-native'); 4 | var Promise = require('bluebird'); // jshint ignore:line 5 | var UserDefaults = NativeModules.RNUserDefaultsIOS; 6 | 7 | var _setObjectForKey = Promise.promisify(UserDefaults.setObjectForKey); 8 | var _setBoolForKey = Promise.promisify(UserDefaults.setBoolForKey); 9 | 10 | var _arrayForKey = Promise.promisify(UserDefaults.arrayForKey); 11 | var _stringForKey = Promise.promisify(UserDefaults.stringForKey); 12 | var _objectForKey = Promise.promisify(UserDefaults.objectForKey); 13 | var _boolForKey = Promise.promisify(UserDefaults.boolForKey); 14 | 15 | var _removeItemForKey = Promise.promisify(UserDefaults.removeObjectForKey); 16 | 17 | var UserDefaults = { 18 | setArrayForKey(array, key) { 19 | return _setObjectForKey(array, key); 20 | }, 21 | setStringForKey(string, key) { 22 | return _setObjectForKey(string, key); 23 | }, 24 | setObjectForKey(object, key) { 25 | return _setObjectForKey(object, key); 26 | }, 27 | setBoolForKey(bool, key) { 28 | return _setBoolForKey(bool, key); 29 | }, 30 | arrayForKey(key) { 31 | return _arrayForKey(key); 32 | }, 33 | stringForKey(key) { 34 | return _stringForKey(key); 35 | }, 36 | objectForKey(key) { 37 | return _objectForKey(key); 38 | }, 39 | boolForKey(key) { 40 | return _boolForKey(key); 41 | }, 42 | removeItemForKey(key) { 43 | return _removeItemForKey(key); 44 | } 45 | }; 46 | 47 | module.exports = UserDefaults; 48 | -------------------------------------------------------------------------------- /RNUserDefaultsIOS.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 038AE8B5157A10AE882E564B /* libPods-RNUserDefaultsIOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F02F74958A49880AC1BFF32E /* libPods-RNUserDefaultsIOSTests.a */; }; 11 | 559FCEFB1B06A72F003129B0 /* libRNUserDefaultsIOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 559FCEEF1B06A72F003129B0 /* libRNUserDefaultsIOS.a */; }; 12 | 559FCF0A1B06A9D4003129B0 /* UserDefaultsManagerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 559FCF091B06A9D4003129B0 /* UserDefaultsManagerSpec.m */; }; 13 | 559FCF0F1B06AA3C003129B0 /* RNUserDefaultsIOS.m in Sources */ = {isa = PBXBuildFile; fileRef = 559FCF0D1B06AA3C003129B0 /* RNUserDefaultsIOS.m */; }; 14 | 559FCF101B06AA3C003129B0 /* UserDefaultsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 559FCF0E1B06AA3C003129B0 /* UserDefaultsManager.m */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXContainerItemProxy section */ 18 | 559FCEFC1B06A72F003129B0 /* PBXContainerItemProxy */ = { 19 | isa = PBXContainerItemProxy; 20 | containerPortal = 559FCEE71B06A72F003129B0 /* Project object */; 21 | proxyType = 1; 22 | remoteGlobalIDString = 559FCEEE1B06A72F003129B0; 23 | remoteInfo = RNUserDefaultsIOS; 24 | }; 25 | /* End PBXContainerItemProxy section */ 26 | 27 | /* Begin PBXCopyFilesBuildPhase section */ 28 | 559FCEED1B06A72F003129B0 /* CopyFiles */ = { 29 | isa = PBXCopyFilesBuildPhase; 30 | buildActionMask = 2147483647; 31 | dstPath = "include/$(PRODUCT_NAME)"; 32 | dstSubfolderSpec = 16; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXCopyFilesBuildPhase section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | 559FCEEF1B06A72F003129B0 /* libRNUserDefaultsIOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNUserDefaultsIOS.a; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | 559FCEFA1B06A72F003129B0 /* RNUserDefaultsIOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RNUserDefaultsIOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 559FCF001B06A72F003129B0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | 559FCF091B06A9D4003129B0 /* UserDefaultsManagerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UserDefaultsManagerSpec.m; sourceTree = ""; }; 44 | 559FCF0B1B06AA3C003129B0 /* RNUserDefaultsIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNUserDefaultsIOS.h; sourceTree = ""; }; 45 | 559FCF0C1B06AA3C003129B0 /* UserDefaultsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserDefaultsManager.h; sourceTree = ""; }; 46 | 559FCF0D1B06AA3C003129B0 /* RNUserDefaultsIOS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNUserDefaultsIOS.m; sourceTree = ""; }; 47 | 559FCF0E1B06AA3C003129B0 /* UserDefaultsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UserDefaultsManager.m; sourceTree = ""; }; 48 | 809831CEBAB242911E70061A /* Pods-RNUserDefaultsIOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNUserDefaultsIOSTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RNUserDefaultsIOSTests/Pods-RNUserDefaultsIOSTests.debug.xcconfig"; sourceTree = ""; }; 49 | 8A87FCE5AE5E0842B36D1575 /* Pods-RNUserDefaultsIOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNUserDefaultsIOSTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-RNUserDefaultsIOSTests/Pods-RNUserDefaultsIOSTests.release.xcconfig"; sourceTree = ""; }; 50 | F02F74958A49880AC1BFF32E /* libPods-RNUserDefaultsIOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNUserDefaultsIOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | /* End PBXFileReference section */ 52 | 53 | /* Begin PBXFrameworksBuildPhase section */ 54 | 559FCEEC1B06A72F003129B0 /* Frameworks */ = { 55 | isa = PBXFrameworksBuildPhase; 56 | buildActionMask = 2147483647; 57 | files = ( 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | 559FCEF71B06A72F003129B0 /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | 559FCEFB1B06A72F003129B0 /* libRNUserDefaultsIOS.a in Frameworks */, 66 | 038AE8B5157A10AE882E564B /* libPods-RNUserDefaultsIOSTests.a in Frameworks */, 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | /* End PBXFrameworksBuildPhase section */ 71 | 72 | /* Begin PBXGroup section */ 73 | 559FCEE61B06A72F003129B0 = { 74 | isa = PBXGroup; 75 | children = ( 76 | 559FCEF11B06A72F003129B0 /* RNUserDefaultsIOS */, 77 | 559FCEFE1B06A72F003129B0 /* RNUserDefaultsIOSTests */, 78 | 559FCEF01B06A72F003129B0 /* Products */, 79 | EA37BBBB1DDAE5C3DA9BAB33 /* Pods */, 80 | 5FAE7E5390ED5FA8958BD4D2 /* Frameworks */, 81 | ); 82 | sourceTree = ""; 83 | }; 84 | 559FCEF01B06A72F003129B0 /* Products */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 559FCEEF1B06A72F003129B0 /* libRNUserDefaultsIOS.a */, 88 | 559FCEFA1B06A72F003129B0 /* RNUserDefaultsIOSTests.xctest */, 89 | ); 90 | name = Products; 91 | sourceTree = ""; 92 | }; 93 | 559FCEF11B06A72F003129B0 /* RNUserDefaultsIOS */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 559FCF0C1B06AA3C003129B0 /* UserDefaultsManager.h */, 97 | 559FCF0E1B06AA3C003129B0 /* UserDefaultsManager.m */, 98 | 559FCF0B1B06AA3C003129B0 /* RNUserDefaultsIOS.h */, 99 | 559FCF0D1B06AA3C003129B0 /* RNUserDefaultsIOS.m */, 100 | ); 101 | path = RNUserDefaultsIOS; 102 | sourceTree = ""; 103 | }; 104 | 559FCEFE1B06A72F003129B0 /* RNUserDefaultsIOSTests */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 559FCEFF1B06A72F003129B0 /* Supporting Files */, 108 | 559FCF091B06A9D4003129B0 /* UserDefaultsManagerSpec.m */, 109 | ); 110 | path = RNUserDefaultsIOSTests; 111 | sourceTree = ""; 112 | }; 113 | 559FCEFF1B06A72F003129B0 /* Supporting Files */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 559FCF001B06A72F003129B0 /* Info.plist */, 117 | ); 118 | name = "Supporting Files"; 119 | sourceTree = ""; 120 | }; 121 | 5FAE7E5390ED5FA8958BD4D2 /* Frameworks */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | F02F74958A49880AC1BFF32E /* libPods-RNUserDefaultsIOSTests.a */, 125 | ); 126 | name = Frameworks; 127 | sourceTree = ""; 128 | }; 129 | EA37BBBB1DDAE5C3DA9BAB33 /* Pods */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | 809831CEBAB242911E70061A /* Pods-RNUserDefaultsIOSTests.debug.xcconfig */, 133 | 8A87FCE5AE5E0842B36D1575 /* Pods-RNUserDefaultsIOSTests.release.xcconfig */, 134 | ); 135 | name = Pods; 136 | sourceTree = ""; 137 | }; 138 | /* End PBXGroup section */ 139 | 140 | /* Begin PBXNativeTarget section */ 141 | 559FCEEE1B06A72F003129B0 /* RNUserDefaultsIOS */ = { 142 | isa = PBXNativeTarget; 143 | buildConfigurationList = 559FCF031B06A72F003129B0 /* Build configuration list for PBXNativeTarget "RNUserDefaultsIOS" */; 144 | buildPhases = ( 145 | 559FCEEB1B06A72F003129B0 /* Sources */, 146 | 559FCEEC1B06A72F003129B0 /* Frameworks */, 147 | 559FCEED1B06A72F003129B0 /* CopyFiles */, 148 | ); 149 | buildRules = ( 150 | ); 151 | dependencies = ( 152 | ); 153 | name = RNUserDefaultsIOS; 154 | productName = RNUserDefaultsIOS; 155 | productReference = 559FCEEF1B06A72F003129B0 /* libRNUserDefaultsIOS.a */; 156 | productType = "com.apple.product-type.library.static"; 157 | }; 158 | 559FCEF91B06A72F003129B0 /* RNUserDefaultsIOSTests */ = { 159 | isa = PBXNativeTarget; 160 | buildConfigurationList = 559FCF061B06A72F003129B0 /* Build configuration list for PBXNativeTarget "RNUserDefaultsIOSTests" */; 161 | buildPhases = ( 162 | 2BA2CBA3E34B07FFD2FC9F5F /* Check Pods Manifest.lock */, 163 | 559FCEF61B06A72F003129B0 /* Sources */, 164 | 559FCEF71B06A72F003129B0 /* Frameworks */, 165 | 559FCEF81B06A72F003129B0 /* Resources */, 166 | DFC6A04873ACFB11FD013134 /* Copy Pods Resources */, 167 | ); 168 | buildRules = ( 169 | ); 170 | dependencies = ( 171 | 559FCEFD1B06A72F003129B0 /* PBXTargetDependency */, 172 | ); 173 | name = RNUserDefaultsIOSTests; 174 | productName = RNUserDefaultsIOSTests; 175 | productReference = 559FCEFA1B06A72F003129B0 /* RNUserDefaultsIOSTests.xctest */; 176 | productType = "com.apple.product-type.bundle.unit-test"; 177 | }; 178 | /* End PBXNativeTarget section */ 179 | 180 | /* Begin PBXProject section */ 181 | 559FCEE71B06A72F003129B0 /* Project object */ = { 182 | isa = PBXProject; 183 | attributes = { 184 | LastUpgradeCheck = 0620; 185 | ORGANIZATIONNAME = "Dave Sibiski"; 186 | TargetAttributes = { 187 | 559FCEEE1B06A72F003129B0 = { 188 | CreatedOnToolsVersion = 6.2; 189 | }; 190 | 559FCEF91B06A72F003129B0 = { 191 | CreatedOnToolsVersion = 6.2; 192 | }; 193 | }; 194 | }; 195 | buildConfigurationList = 559FCEEA1B06A72F003129B0 /* Build configuration list for PBXProject "RNUserDefaultsIOS" */; 196 | compatibilityVersion = "Xcode 3.2"; 197 | developmentRegion = English; 198 | hasScannedForEncodings = 0; 199 | knownRegions = ( 200 | en, 201 | ); 202 | mainGroup = 559FCEE61B06A72F003129B0; 203 | productRefGroup = 559FCEF01B06A72F003129B0 /* Products */; 204 | projectDirPath = ""; 205 | projectRoot = ""; 206 | targets = ( 207 | 559FCEEE1B06A72F003129B0 /* RNUserDefaultsIOS */, 208 | 559FCEF91B06A72F003129B0 /* RNUserDefaultsIOSTests */, 209 | ); 210 | }; 211 | /* End PBXProject section */ 212 | 213 | /* Begin PBXResourcesBuildPhase section */ 214 | 559FCEF81B06A72F003129B0 /* Resources */ = { 215 | isa = PBXResourcesBuildPhase; 216 | buildActionMask = 2147483647; 217 | files = ( 218 | ); 219 | runOnlyForDeploymentPostprocessing = 0; 220 | }; 221 | /* End PBXResourcesBuildPhase section */ 222 | 223 | /* Begin PBXShellScriptBuildPhase section */ 224 | 2BA2CBA3E34B07FFD2FC9F5F /* Check Pods Manifest.lock */ = { 225 | isa = PBXShellScriptBuildPhase; 226 | buildActionMask = 2147483647; 227 | files = ( 228 | ); 229 | inputPaths = ( 230 | ); 231 | name = "Check Pods Manifest.lock"; 232 | outputPaths = ( 233 | ); 234 | runOnlyForDeploymentPostprocessing = 0; 235 | shellPath = /bin/sh; 236 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 237 | showEnvVarsInLog = 0; 238 | }; 239 | DFC6A04873ACFB11FD013134 /* Copy Pods Resources */ = { 240 | isa = PBXShellScriptBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | ); 244 | inputPaths = ( 245 | ); 246 | name = "Copy Pods Resources"; 247 | outputPaths = ( 248 | ); 249 | runOnlyForDeploymentPostprocessing = 0; 250 | shellPath = /bin/sh; 251 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-RNUserDefaultsIOSTests/Pods-RNUserDefaultsIOSTests-resources.sh\"\n"; 252 | showEnvVarsInLog = 0; 253 | }; 254 | /* End PBXShellScriptBuildPhase section */ 255 | 256 | /* Begin PBXSourcesBuildPhase section */ 257 | 559FCEEB1B06A72F003129B0 /* Sources */ = { 258 | isa = PBXSourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | 559FCF101B06AA3C003129B0 /* UserDefaultsManager.m in Sources */, 262 | 559FCF0F1B06AA3C003129B0 /* RNUserDefaultsIOS.m in Sources */, 263 | ); 264 | runOnlyForDeploymentPostprocessing = 0; 265 | }; 266 | 559FCEF61B06A72F003129B0 /* Sources */ = { 267 | isa = PBXSourcesBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | 559FCF0A1B06A9D4003129B0 /* UserDefaultsManagerSpec.m in Sources */, 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | }; 274 | /* End PBXSourcesBuildPhase section */ 275 | 276 | /* Begin PBXTargetDependency section */ 277 | 559FCEFD1B06A72F003129B0 /* PBXTargetDependency */ = { 278 | isa = PBXTargetDependency; 279 | target = 559FCEEE1B06A72F003129B0 /* RNUserDefaultsIOS */; 280 | targetProxy = 559FCEFC1B06A72F003129B0 /* PBXContainerItemProxy */; 281 | }; 282 | /* End PBXTargetDependency section */ 283 | 284 | /* Begin XCBuildConfiguration section */ 285 | 559FCF011B06A72F003129B0 /* Debug */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ALWAYS_SEARCH_USER_PATHS = NO; 289 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 290 | CLANG_CXX_LIBRARY = "libc++"; 291 | CLANG_ENABLE_MODULES = YES; 292 | CLANG_ENABLE_OBJC_ARC = YES; 293 | CLANG_WARN_BOOL_CONVERSION = YES; 294 | CLANG_WARN_CONSTANT_CONVERSION = YES; 295 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 296 | CLANG_WARN_EMPTY_BODY = YES; 297 | CLANG_WARN_ENUM_CONVERSION = YES; 298 | CLANG_WARN_INT_CONVERSION = YES; 299 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 300 | CLANG_WARN_UNREACHABLE_CODE = YES; 301 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 302 | COPY_PHASE_STRIP = NO; 303 | ENABLE_STRICT_OBJC_MSGSEND = YES; 304 | GCC_C_LANGUAGE_STANDARD = gnu99; 305 | GCC_DYNAMIC_NO_PIC = NO; 306 | GCC_OPTIMIZATION_LEVEL = 0; 307 | GCC_PREPROCESSOR_DEFINITIONS = ( 308 | "DEBUG=1", 309 | "$(inherited)", 310 | ); 311 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 312 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 313 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 314 | GCC_WARN_UNDECLARED_SELECTOR = YES; 315 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 316 | GCC_WARN_UNUSED_FUNCTION = YES; 317 | GCC_WARN_UNUSED_VARIABLE = YES; 318 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 319 | MTL_ENABLE_DEBUG_INFO = YES; 320 | ONLY_ACTIVE_ARCH = YES; 321 | SDKROOT = iphoneos; 322 | }; 323 | name = Debug; 324 | }; 325 | 559FCF021B06A72F003129B0 /* Release */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | ALWAYS_SEARCH_USER_PATHS = NO; 329 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 330 | CLANG_CXX_LIBRARY = "libc++"; 331 | CLANG_ENABLE_MODULES = YES; 332 | CLANG_ENABLE_OBJC_ARC = YES; 333 | CLANG_WARN_BOOL_CONVERSION = YES; 334 | CLANG_WARN_CONSTANT_CONVERSION = YES; 335 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 336 | CLANG_WARN_EMPTY_BODY = YES; 337 | CLANG_WARN_ENUM_CONVERSION = YES; 338 | CLANG_WARN_INT_CONVERSION = YES; 339 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 340 | CLANG_WARN_UNREACHABLE_CODE = YES; 341 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 342 | COPY_PHASE_STRIP = NO; 343 | ENABLE_NS_ASSERTIONS = NO; 344 | ENABLE_STRICT_OBJC_MSGSEND = YES; 345 | GCC_C_LANGUAGE_STANDARD = gnu99; 346 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 347 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 348 | GCC_WARN_UNDECLARED_SELECTOR = YES; 349 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 350 | GCC_WARN_UNUSED_FUNCTION = YES; 351 | GCC_WARN_UNUSED_VARIABLE = YES; 352 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 353 | MTL_ENABLE_DEBUG_INFO = NO; 354 | SDKROOT = iphoneos; 355 | VALIDATE_PRODUCT = YES; 356 | }; 357 | name = Release; 358 | }; 359 | 559FCF041B06A72F003129B0 /* Debug */ = { 360 | isa = XCBuildConfiguration; 361 | buildSettings = { 362 | HEADER_SEARCH_PATHS = ( 363 | "$(inherited)", 364 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 365 | "$(SRCROOT)/../../React/**", 366 | "$(SRCROOT)/../react-native/React/**", 367 | "$(SRCROOT)/node_modules/react-native/React/**", 368 | ); 369 | OTHER_LDFLAGS = "-ObjC"; 370 | PRODUCT_NAME = "$(TARGET_NAME)"; 371 | SKIP_INSTALL = YES; 372 | }; 373 | name = Debug; 374 | }; 375 | 559FCF051B06A72F003129B0 /* Release */ = { 376 | isa = XCBuildConfiguration; 377 | buildSettings = { 378 | HEADER_SEARCH_PATHS = ( 379 | "$(inherited)", 380 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 381 | "$(SRCROOT)/../../React/**", 382 | "$(SRCROOT)/../react-native/React/**", 383 | "$(SRCROOT)/node_modules/react-native/React/**", 384 | ); 385 | OTHER_LDFLAGS = "-ObjC"; 386 | PRODUCT_NAME = "$(TARGET_NAME)"; 387 | SKIP_INSTALL = YES; 388 | }; 389 | name = Release; 390 | }; 391 | 559FCF071B06A72F003129B0 /* Debug */ = { 392 | isa = XCBuildConfiguration; 393 | baseConfigurationReference = 809831CEBAB242911E70061A /* Pods-RNUserDefaultsIOSTests.debug.xcconfig */; 394 | buildSettings = { 395 | FRAMEWORK_SEARCH_PATHS = ( 396 | "$(SDKROOT)/Developer/Library/Frameworks", 397 | "$(inherited)", 398 | ); 399 | GCC_PREPROCESSOR_DEFINITIONS = ( 400 | "DEBUG=1", 401 | "$(inherited)", 402 | ); 403 | INFOPLIST_FILE = RNUserDefaultsIOSTests/Info.plist; 404 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 405 | PRODUCT_NAME = "$(TARGET_NAME)"; 406 | }; 407 | name = Debug; 408 | }; 409 | 559FCF081B06A72F003129B0 /* Release */ = { 410 | isa = XCBuildConfiguration; 411 | baseConfigurationReference = 8A87FCE5AE5E0842B36D1575 /* Pods-RNUserDefaultsIOSTests.release.xcconfig */; 412 | buildSettings = { 413 | FRAMEWORK_SEARCH_PATHS = ( 414 | "$(SDKROOT)/Developer/Library/Frameworks", 415 | "$(inherited)", 416 | ); 417 | INFOPLIST_FILE = RNUserDefaultsIOSTests/Info.plist; 418 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 419 | PRODUCT_NAME = "$(TARGET_NAME)"; 420 | }; 421 | name = Release; 422 | }; 423 | /* End XCBuildConfiguration section */ 424 | 425 | /* Begin XCConfigurationList section */ 426 | 559FCEEA1B06A72F003129B0 /* Build configuration list for PBXProject "RNUserDefaultsIOS" */ = { 427 | isa = XCConfigurationList; 428 | buildConfigurations = ( 429 | 559FCF011B06A72F003129B0 /* Debug */, 430 | 559FCF021B06A72F003129B0 /* Release */, 431 | ); 432 | defaultConfigurationIsVisible = 0; 433 | defaultConfigurationName = Release; 434 | }; 435 | 559FCF031B06A72F003129B0 /* Build configuration list for PBXNativeTarget "RNUserDefaultsIOS" */ = { 436 | isa = XCConfigurationList; 437 | buildConfigurations = ( 438 | 559FCF041B06A72F003129B0 /* Debug */, 439 | 559FCF051B06A72F003129B0 /* Release */, 440 | ); 441 | defaultConfigurationIsVisible = 0; 442 | defaultConfigurationName = Release; 443 | }; 444 | 559FCF061B06A72F003129B0 /* Build configuration list for PBXNativeTarget "RNUserDefaultsIOSTests" */ = { 445 | isa = XCConfigurationList; 446 | buildConfigurations = ( 447 | 559FCF071B06A72F003129B0 /* Debug */, 448 | 559FCF081B06A72F003129B0 /* Release */, 449 | ); 450 | defaultConfigurationIsVisible = 0; 451 | defaultConfigurationName = Release; 452 | }; 453 | /* End XCConfigurationList section */ 454 | }; 455 | rootObject = 559FCEE71B06A72F003129B0 /* Project object */; 456 | } 457 | -------------------------------------------------------------------------------- /RNUserDefaultsIOS.xcodeproj/xcshareddata/xcschemes/RNUserDefaultsIOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /RNUserDefaultsIOS.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /RNUserDefaultsIOS/RNUserDefaultsIOS.h: -------------------------------------------------------------------------------- 1 | // 2 | // RNStandardUserDefaultsIOS.h 3 | // RNStandardUserDefaultsIOS 4 | // 5 | // Created by Dave Sibiski on 5/15/15. 6 | // Copyright (c) 2015 Dave Sibiski. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RCTBridgeModule.h" 11 | 12 | @interface RNUserDefaultsIOS : NSObject 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /RNUserDefaultsIOS/RNUserDefaultsIOS.m: -------------------------------------------------------------------------------- 1 | // 2 | // RNStandardUserDefaultsIOS.m 3 | // RNStandardUserDefaultsIOS 4 | // 5 | // Created by Dave Sibiski on 5/15/15. 6 | // Copyright (c) 2015 Dave Sibiski. All rights reserved. 7 | // 8 | 9 | #import "RNUserDefaultsIOS.h" 10 | #import "UserDefaultsManager.h" 11 | 12 | @implementation RNUserDefaultsIOS 13 | 14 | RCT_EXPORT_MODULE() 15 | 16 | RCT_EXPORT_METHOD(setObjectForKey:(id)object key:(NSString *)key callback:(RCTResponseSenderBlock)callback) { 17 | 18 | [UserDefaultsManager setObject:object forKey:key]; 19 | 20 | callback(@[[NSNull null], @"success"]); 21 | } 22 | 23 | RCT_EXPORT_METHOD(setBoolForKey:(BOOL)value key:(NSString *)key callback:(RCTResponseSenderBlock)callback) { 24 | 25 | [UserDefaultsManager setBool:value forKey:key]; 26 | 27 | callback(@[[NSNull null], @"success"]); 28 | } 29 | 30 | RCT_EXPORT_METHOD(removeObjectForKey:(NSString *)key callback:(RCTResponseSenderBlock)callback) { 31 | 32 | [UserDefaultsManager removeObjectForKey:key]; 33 | 34 | callback(@[[NSNull null], @"success"]); 35 | } 36 | 37 | RCT_EXPORT_METHOD(arrayForKey:(NSString *)key callback:(RCTResponseSenderBlock)callback) { 38 | 39 | id response = [UserDefaultsManager arrayForKey:key]; 40 | 41 | if (response) { 42 | 43 | callback(@[[NSNull null], response]); 44 | } 45 | else { 46 | 47 | callback(@[[NSNull null], [NSNull null]]); 48 | } 49 | } 50 | 51 | RCT_EXPORT_METHOD(stringForKey:(NSString *)key callback:(RCTResponseSenderBlock)callback) { 52 | 53 | id response = [UserDefaultsManager stringForKey:key]; 54 | 55 | if (response) { 56 | 57 | callback(@[[NSNull null], response]); 58 | } 59 | else { 60 | 61 | callback(@[[NSNull null], [NSNull null]]); 62 | } 63 | } 64 | 65 | RCT_EXPORT_METHOD(objectForKey:(NSString *)key callback:(RCTResponseSenderBlock)callback) { 66 | 67 | id response = [UserDefaultsManager objectForKey:key]; 68 | 69 | if (response) { 70 | 71 | callback(@[[NSNull null], response]); 72 | } 73 | else { 74 | 75 | callback(@[[NSNull null], [NSNull null]]); 76 | } 77 | } 78 | 79 | RCT_EXPORT_METHOD(boolForKey:(NSString *)key callback:(RCTResponseSenderBlock)callback) { 80 | 81 | bool response = [UserDefaultsManager boolForKey:key]; 82 | 83 | callback(@[[NSNull null], [NSNumber numberWithBool:response]]); 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /RNUserDefaultsIOS/UserDefaultsManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // StandardUserDefaultsManager.h 3 | // RNStandardUserDefaultsIOS 4 | // 5 | // Created by Dave Sibiski on 5/15/15. 6 | // Copyright (c) 2015 Dave Sibiski. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UserDefaultsManager : NSObject 12 | 13 | + (void)setObject:(id)object forKey:(NSString *)key; 14 | 15 | + (void)setBool:(bool)value forKey:(NSString *)key; 16 | 17 | + (void)removeObjectForKey:(NSString *)key; 18 | 19 | + (NSArray *)arrayForKey:(NSString *)key; 20 | 21 | + (NSString *)stringForKey:(NSString *)key; 22 | 23 | + (id)objectForKey:(NSString *)key; 24 | 25 | + (bool)boolForKey:(NSString *)key; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /RNUserDefaultsIOS/UserDefaultsManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // StandardUserDefaultsManager.m 3 | // RNStandardUserDefaultsIOS 4 | // 5 | // Created by Dave Sibiski on 5/15/15. 6 | // Copyright (c) 2015 Dave Sibiski. All rights reserved. 7 | // 8 | 9 | #import "UserDefaultsManager.h" 10 | 11 | @implementation UserDefaultsManager 12 | 13 | + (void)setObject:(id)object forKey:(NSString *)key { 14 | 15 | [[NSUserDefaults standardUserDefaults] setObject:object forKey:key]; 16 | } 17 | 18 | + (void)setBool:(bool)value forKey:(NSString *)key { 19 | 20 | [[NSUserDefaults standardUserDefaults] setBool:value forKey:key]; 21 | } 22 | 23 | + (void)removeObjectForKey:(NSString *)key { 24 | 25 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:key]; 26 | } 27 | 28 | + (NSArray *)arrayForKey:(NSString *)key { 29 | 30 | return [[NSUserDefaults standardUserDefaults] arrayForKey:key]; 31 | } 32 | 33 | + (NSString *)stringForKey:(NSString *)key { 34 | 35 | return [[NSUserDefaults standardUserDefaults] stringForKey:key]; 36 | } 37 | 38 | + (id)objectForKey:(NSString *)key { 39 | 40 | return [[NSUserDefaults standardUserDefaults] objectForKey:key]; 41 | } 42 | 43 | + (bool)boolForKey:(NSString *)key { 44 | 45 | return [[NSUserDefaults standardUserDefaults] boolForKey:key]; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /RNUserDefaultsIOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.dsibiski.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /RNUserDefaultsIOSTests/UserDefaultsManagerSpec.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "Specta.h" 3 | 4 | #define EXP_SHORTHAND 5 | #import "Expecta.h" 6 | 7 | #import "UserDefaultsManager.h" 8 | 9 | @interface UserDefaultsManager (Test) 10 | @end 11 | 12 | SpecBegin(UserDefaultsManager) 13 | 14 | describe(@"UserDefaultsManager", ^{ 15 | 16 | __block NSUserDefaults *userDefaults; 17 | 18 | beforeEach(^{ 19 | 20 | userDefaults = [NSUserDefaults standardUserDefaults]; 21 | 22 | }); 23 | 24 | describe(@"writing", ^{ 25 | 26 | describe(@"#setObject:forKey:", ^{ 27 | 28 | it(@"sets a string for given key", ^{ 29 | 30 | [UserDefaultsManager setObject:@"someString" forKey:@"anyKey"]; 31 | 32 | NSString *sut = [userDefaults objectForKey:@"anyKey"]; 33 | 34 | expect(sut).to.equal(@"someString"); 35 | 36 | }); 37 | 38 | it(@"sets an array for a given key", ^{ 39 | 40 | [UserDefaultsManager setObject:@[@"someStringInAnArray"] forKey:@"anyKey"]; 41 | 42 | NSArray *sut = [userDefaults arrayForKey:@"anyKey"]; 43 | 44 | expect(sut).to.equal(@[@"someStringInAnArray"]); 45 | 46 | }); 47 | 48 | }); 49 | 50 | describe(@"#setBool:forKey:", ^{ 51 | 52 | it(@"sets a bool for given key", ^{ 53 | 54 | [UserDefaultsManager setBool:YES forKey:@"anyKey"]; 55 | 56 | BOOL sut = [userDefaults boolForKey:@"anyKey"]; 57 | 58 | expect(sut).to.equal(YES); 59 | 60 | }); 61 | 62 | it(@"sets a different bool for given key", ^{ 63 | 64 | [UserDefaultsManager setBool:NO forKey:@"anyKey"]; 65 | 66 | BOOL sut = [userDefaults boolForKey:@"anyKey"]; 67 | 68 | expect(sut).to.equal(NO); 69 | 70 | }); 71 | 72 | }); 73 | 74 | describe(@"#removeObjectForKey:", ^{ 75 | 76 | it(@"removes the object for given key", ^{ 77 | 78 | [userDefaults setObject:@"anyValue" forKey:@"objectToRemove"]; 79 | 80 | [UserDefaultsManager removeObjectForKey:@"objectToRemove"]; 81 | 82 | expect([userDefaults objectForKey:@"objectToRemove"]).to.beNil(); 83 | 84 | }); 85 | 86 | it(@"removes a boolean value for given key", ^{ 87 | 88 | [userDefaults setBool:YES forKey:@"objectToRemove"]; 89 | 90 | [UserDefaultsManager removeObjectForKey:@"objectToRemove"]; 91 | 92 | expect([userDefaults boolForKey:@"objectToRemove"]).to.equal(NO); 93 | 94 | }); 95 | 96 | }); 97 | 98 | }); 99 | 100 | describe(@"reading", ^{ 101 | 102 | describe(@"#arrayForKey:", ^{ 103 | 104 | it(@"returns the correct array", ^{ 105 | 106 | [userDefaults setValue:@[@"anyArray"] forKey:@"anyArray"]; 107 | 108 | NSArray *sut = [UserDefaultsManager arrayForKey:@"anyArray"]; 109 | 110 | expect(sut).to.equal(@[@"anyArray"]); 111 | 112 | }); 113 | 114 | it(@"returns the correct array", ^{ 115 | 116 | [userDefaults setValue:@[@"different", @"array"] forKey:@"anyArray"]; 117 | 118 | NSArray *sut = [UserDefaultsManager arrayForKey:@"anyArray"]; 119 | 120 | expect(sut).to.equal(@[@"different", @"array"]); 121 | 122 | }); 123 | 124 | }); 125 | 126 | describe(@"#stringForKey:", ^{ 127 | 128 | it(@"returns the correct string", ^{ 129 | 130 | [userDefaults setValue:@"anyValue" forKey:@"anyKey"]; 131 | 132 | NSString *sut = [UserDefaultsManager stringForKey:@"anyKey"]; 133 | 134 | expect(sut).to.equal(@"anyValue"); 135 | 136 | }); 137 | 138 | it(@"returns a different string", ^{ 139 | 140 | [userDefaults setValue:@"aDifferentValue" forKey:@"anyKey"]; 141 | 142 | NSString *sut = [UserDefaultsManager stringForKey:@"anyKey"]; 143 | 144 | expect(sut).to.equal(@"aDifferentValue"); 145 | 146 | }); 147 | 148 | }); 149 | 150 | describe(@"#objectForKey:", ^{ 151 | 152 | it(@"returns the correct Dictionary", ^{ 153 | 154 | NSDictionary *testDict = @{@"anything" : @"something"}; 155 | 156 | [userDefaults setObject:testDict forKey:@"anyKey"]; 157 | 158 | NSDictionary *sut = [UserDefaultsManager objectForKey:@"anyKey"]; 159 | 160 | expect(sut).to.equal(testDict); 161 | 162 | }); 163 | 164 | it(@"returns a different Dictionary", ^{ 165 | 166 | NSDictionary *testDict = @{@"anythingElse" : @"somethingElse"}; 167 | 168 | [userDefaults setObject:testDict forKey:@"anyKey"]; 169 | 170 | NSDictionary *sut = [UserDefaultsManager objectForKey:@"anyKey"]; 171 | 172 | expect(sut).to.equal(testDict); 173 | 174 | }); 175 | 176 | }); 177 | 178 | describe(@"#boolForKey:", ^{ 179 | 180 | it(@"returns the correct Boolean value", ^{ 181 | 182 | [userDefaults setBool:YES forKey:@"anyKey"]; 183 | 184 | BOOL sut = [UserDefaultsManager boolForKey:@"anyKey"]; 185 | 186 | expect(sut).to.equal(YES); 187 | 188 | }); 189 | 190 | it(@"returns a different Boolean value", ^{ 191 | 192 | [userDefaults setBool:NO forKey:@"anyKey"]; 193 | 194 | BOOL sut = [UserDefaultsManager boolForKey:@"anyKey"]; 195 | 196 | expect(sut).to.equal(NO); 197 | 198 | }); 199 | }); 200 | 201 | }); 202 | 203 | afterEach(^{ 204 | 205 | userDefaults = nil; 206 | 207 | }); 208 | 209 | }); 210 | 211 | SpecEnd -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-userdefaults-ios", 3 | "version": "0.1.3", 4 | "description": "React Native Module for NSUserDefaults", 5 | "main": "RNUserDefaultsIOS.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git@github.com:dsibiski/react-native-userdefaults-ios.git" 12 | }, 13 | "files": [ 14 | "RNUserDefaultsIOS.xcodeproj", 15 | "RNUserDefaultsIOS/RNUserDefaultsIOS.h", 16 | "RNUserDefaultsIOS/RNUserDefaultsIOS.m", 17 | "RNUserDefaultsIOS/UserDefaultsManager.h", 18 | "RNUserDefaultsIOS/UserDefaultsManager.m", 19 | "RNUserDefaultsIOS.js", 20 | "README.md" 21 | ], 22 | "keywords": [ 23 | "react-component", 24 | "react-native", 25 | "ios", 26 | "nsuserdefaults", 27 | "standarduserdefaults", 28 | "userdefaults" 29 | ], 30 | "author": "Dave Sibiski (https://github.com/dsibiski)", 31 | "license": "MIT", 32 | "dependencies": { 33 | "bluebird": "^2.9.25" 34 | }, 35 | "peerDependencies": { 36 | "react-native": ">= 0.4.4 < 1" 37 | } 38 | } 39 | --------------------------------------------------------------------------------