├── .gitignore ├── LICENSE ├── README.md ├── UserDefaultsEVO.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── zz.xcuserdatad │ └── xcschemes │ ├── UserDefaultsEVO.xcscheme │ └── xcschememanagement.plist ├── UserDefaultsEVO ├── Info.plist ├── UserDefaultsEVO.h └── UserDefaultsEVO.swift └── UserDefaultsEVOTests ├── Info.plist └── UserDefaultsEVOTests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | Breakpoints_v2.xcbkptlist 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Zhuo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UserDefaultsEVO 2 | Using UserDefaults in a swift way 3 | # Usage 4 | define a Enum which rawValue is String, comform to `UserDefaultSettable` 5 | 6 | ```swift 7 | extension UserDefaults { 8 | enum TestData: String,UserDefaultSettable { 9 | case name 10 | } 11 | } 12 | ``` 13 | store value: 14 | ```swift 15 | UserDefaults.TestData.name.store(value: "name") 16 | ``` 17 | get value form UserDefaults: 18 | ```swift 19 |  let storeValue = UserDefaults.TestData.name.storedString 20 | ``` -------------------------------------------------------------------------------- /UserDefaultsEVO.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3A0CA9F51E5C6F9800D3B9CF /* UserDefaultsEVO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A0CA9EB1E5C6F9800D3B9CF /* UserDefaultsEVO.framework */; }; 11 | 3A0CA9FA1E5C6F9800D3B9CF /* UserDefaultsEVOTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A0CA9F91E5C6F9800D3B9CF /* UserDefaultsEVOTests.swift */; }; 12 | 3A0CA9FC1E5C6F9800D3B9CF /* UserDefaultsEVO.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A0CA9EE1E5C6F9800D3B9CF /* UserDefaultsEVO.h */; settings = {ATTRIBUTES = (Public, ); }; }; 13 | 3A0CAA061E5C6FB800D3B9CF /* UserDefaultsEVO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A0CAA051E5C6FB800D3B9CF /* UserDefaultsEVO.swift */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXContainerItemProxy section */ 17 | 3A0CA9F61E5C6F9800D3B9CF /* PBXContainerItemProxy */ = { 18 | isa = PBXContainerItemProxy; 19 | containerPortal = 3A0CA9E21E5C6F9800D3B9CF /* Project object */; 20 | proxyType = 1; 21 | remoteGlobalIDString = 3A0CA9EA1E5C6F9800D3B9CF; 22 | remoteInfo = UserDefaultsEVO; 23 | }; 24 | /* End PBXContainerItemProxy section */ 25 | 26 | /* Begin PBXFileReference section */ 27 | 3A0CA9EB1E5C6F9800D3B9CF /* UserDefaultsEVO.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UserDefaultsEVO.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 3A0CA9EE1E5C6F9800D3B9CF /* UserDefaultsEVO.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserDefaultsEVO.h; sourceTree = ""; }; 29 | 3A0CA9EF1E5C6F9800D3B9CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 3A0CA9F41E5C6F9800D3B9CF /* UserDefaultsEVOTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UserDefaultsEVOTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 3A0CA9F91E5C6F9800D3B9CF /* UserDefaultsEVOTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsEVOTests.swift; sourceTree = ""; }; 32 | 3A0CA9FB1E5C6F9800D3B9CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 3A0CAA051E5C6FB800D3B9CF /* UserDefaultsEVO.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDefaultsEVO.swift; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | 3A0CA9E71E5C6F9800D3B9CF /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | ); 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | 3A0CA9F11E5C6F9800D3B9CF /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | 3A0CA9F51E5C6F9800D3B9CF /* UserDefaultsEVO.framework in Frameworks */, 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXFrameworksBuildPhase section */ 53 | 54 | /* Begin PBXGroup section */ 55 | 3A0CA9E11E5C6F9800D3B9CF = { 56 | isa = PBXGroup; 57 | children = ( 58 | 3A0CA9ED1E5C6F9800D3B9CF /* UserDefaultsEVO */, 59 | 3A0CA9F81E5C6F9800D3B9CF /* UserDefaultsEVOTests */, 60 | 3A0CA9EC1E5C6F9800D3B9CF /* Products */, 61 | ); 62 | sourceTree = ""; 63 | }; 64 | 3A0CA9EC1E5C6F9800D3B9CF /* Products */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 3A0CA9EB1E5C6F9800D3B9CF /* UserDefaultsEVO.framework */, 68 | 3A0CA9F41E5C6F9800D3B9CF /* UserDefaultsEVOTests.xctest */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | 3A0CA9ED1E5C6F9800D3B9CF /* UserDefaultsEVO */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 3A0CA9EE1E5C6F9800D3B9CF /* UserDefaultsEVO.h */, 77 | 3A0CA9EF1E5C6F9800D3B9CF /* Info.plist */, 78 | 3A0CAA051E5C6FB800D3B9CF /* UserDefaultsEVO.swift */, 79 | ); 80 | path = UserDefaultsEVO; 81 | sourceTree = ""; 82 | }; 83 | 3A0CA9F81E5C6F9800D3B9CF /* UserDefaultsEVOTests */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 3A0CA9F91E5C6F9800D3B9CF /* UserDefaultsEVOTests.swift */, 87 | 3A0CA9FB1E5C6F9800D3B9CF /* Info.plist */, 88 | ); 89 | path = UserDefaultsEVOTests; 90 | sourceTree = ""; 91 | }; 92 | /* End PBXGroup section */ 93 | 94 | /* Begin PBXHeadersBuildPhase section */ 95 | 3A0CA9E81E5C6F9800D3B9CF /* Headers */ = { 96 | isa = PBXHeadersBuildPhase; 97 | buildActionMask = 2147483647; 98 | files = ( 99 | 3A0CA9FC1E5C6F9800D3B9CF /* UserDefaultsEVO.h in Headers */, 100 | ); 101 | runOnlyForDeploymentPostprocessing = 0; 102 | }; 103 | /* End PBXHeadersBuildPhase section */ 104 | 105 | /* Begin PBXNativeTarget section */ 106 | 3A0CA9EA1E5C6F9800D3B9CF /* UserDefaultsEVO */ = { 107 | isa = PBXNativeTarget; 108 | buildConfigurationList = 3A0CA9FF1E5C6F9800D3B9CF /* Build configuration list for PBXNativeTarget "UserDefaultsEVO" */; 109 | buildPhases = ( 110 | 3A0CA9E61E5C6F9800D3B9CF /* Sources */, 111 | 3A0CA9E71E5C6F9800D3B9CF /* Frameworks */, 112 | 3A0CA9E81E5C6F9800D3B9CF /* Headers */, 113 | 3A0CA9E91E5C6F9800D3B9CF /* Resources */, 114 | ); 115 | buildRules = ( 116 | ); 117 | dependencies = ( 118 | ); 119 | name = UserDefaultsEVO; 120 | productName = UserDefaultsEVO; 121 | productReference = 3A0CA9EB1E5C6F9800D3B9CF /* UserDefaultsEVO.framework */; 122 | productType = "com.apple.product-type.framework"; 123 | }; 124 | 3A0CA9F31E5C6F9800D3B9CF /* UserDefaultsEVOTests */ = { 125 | isa = PBXNativeTarget; 126 | buildConfigurationList = 3A0CAA021E5C6F9800D3B9CF /* Build configuration list for PBXNativeTarget "UserDefaultsEVOTests" */; 127 | buildPhases = ( 128 | 3A0CA9F01E5C6F9800D3B9CF /* Sources */, 129 | 3A0CA9F11E5C6F9800D3B9CF /* Frameworks */, 130 | 3A0CA9F21E5C6F9800D3B9CF /* Resources */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | 3A0CA9F71E5C6F9800D3B9CF /* PBXTargetDependency */, 136 | ); 137 | name = UserDefaultsEVOTests; 138 | productName = UserDefaultsEVOTests; 139 | productReference = 3A0CA9F41E5C6F9800D3B9CF /* UserDefaultsEVOTests.xctest */; 140 | productType = "com.apple.product-type.bundle.unit-test"; 141 | }; 142 | /* End PBXNativeTarget section */ 143 | 144 | /* Begin PBXProject section */ 145 | 3A0CA9E21E5C6F9800D3B9CF /* Project object */ = { 146 | isa = PBXProject; 147 | attributes = { 148 | LastSwiftUpdateCheck = 0820; 149 | LastUpgradeCheck = 0820; 150 | ORGANIZATIONNAME = "卓同学"; 151 | TargetAttributes = { 152 | 3A0CA9EA1E5C6F9800D3B9CF = { 153 | CreatedOnToolsVersion = 8.2.1; 154 | LastSwiftMigration = 0820; 155 | ProvisioningStyle = Automatic; 156 | }; 157 | 3A0CA9F31E5C6F9800D3B9CF = { 158 | CreatedOnToolsVersion = 8.2.1; 159 | ProvisioningStyle = Automatic; 160 | }; 161 | }; 162 | }; 163 | buildConfigurationList = 3A0CA9E51E5C6F9800D3B9CF /* Build configuration list for PBXProject "UserDefaultsEVO" */; 164 | compatibilityVersion = "Xcode 3.2"; 165 | developmentRegion = English; 166 | hasScannedForEncodings = 0; 167 | knownRegions = ( 168 | en, 169 | ); 170 | mainGroup = 3A0CA9E11E5C6F9800D3B9CF; 171 | productRefGroup = 3A0CA9EC1E5C6F9800D3B9CF /* Products */; 172 | projectDirPath = ""; 173 | projectRoot = ""; 174 | targets = ( 175 | 3A0CA9EA1E5C6F9800D3B9CF /* UserDefaultsEVO */, 176 | 3A0CA9F31E5C6F9800D3B9CF /* UserDefaultsEVOTests */, 177 | ); 178 | }; 179 | /* End PBXProject section */ 180 | 181 | /* Begin PBXResourcesBuildPhase section */ 182 | 3A0CA9E91E5C6F9800D3B9CF /* Resources */ = { 183 | isa = PBXResourcesBuildPhase; 184 | buildActionMask = 2147483647; 185 | files = ( 186 | ); 187 | runOnlyForDeploymentPostprocessing = 0; 188 | }; 189 | 3A0CA9F21E5C6F9800D3B9CF /* Resources */ = { 190 | isa = PBXResourcesBuildPhase; 191 | buildActionMask = 2147483647; 192 | files = ( 193 | ); 194 | runOnlyForDeploymentPostprocessing = 0; 195 | }; 196 | /* End PBXResourcesBuildPhase section */ 197 | 198 | /* Begin PBXSourcesBuildPhase section */ 199 | 3A0CA9E61E5C6F9800D3B9CF /* Sources */ = { 200 | isa = PBXSourcesBuildPhase; 201 | buildActionMask = 2147483647; 202 | files = ( 203 | 3A0CAA061E5C6FB800D3B9CF /* UserDefaultsEVO.swift in Sources */, 204 | ); 205 | runOnlyForDeploymentPostprocessing = 0; 206 | }; 207 | 3A0CA9F01E5C6F9800D3B9CF /* Sources */ = { 208 | isa = PBXSourcesBuildPhase; 209 | buildActionMask = 2147483647; 210 | files = ( 211 | 3A0CA9FA1E5C6F9800D3B9CF /* UserDefaultsEVOTests.swift in Sources */, 212 | ); 213 | runOnlyForDeploymentPostprocessing = 0; 214 | }; 215 | /* End PBXSourcesBuildPhase section */ 216 | 217 | /* Begin PBXTargetDependency section */ 218 | 3A0CA9F71E5C6F9800D3B9CF /* PBXTargetDependency */ = { 219 | isa = PBXTargetDependency; 220 | target = 3A0CA9EA1E5C6F9800D3B9CF /* UserDefaultsEVO */; 221 | targetProxy = 3A0CA9F61E5C6F9800D3B9CF /* PBXContainerItemProxy */; 222 | }; 223 | /* End PBXTargetDependency section */ 224 | 225 | /* Begin XCBuildConfiguration section */ 226 | 3A0CA9FD1E5C6F9800D3B9CF /* Debug */ = { 227 | isa = XCBuildConfiguration; 228 | buildSettings = { 229 | ALWAYS_SEARCH_USER_PATHS = NO; 230 | CLANG_ANALYZER_NONNULL = YES; 231 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 232 | CLANG_CXX_LIBRARY = "libc++"; 233 | CLANG_ENABLE_MODULES = YES; 234 | CLANG_ENABLE_OBJC_ARC = YES; 235 | CLANG_WARN_BOOL_CONVERSION = YES; 236 | CLANG_WARN_CONSTANT_CONVERSION = YES; 237 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 238 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 239 | CLANG_WARN_EMPTY_BODY = YES; 240 | CLANG_WARN_ENUM_CONVERSION = YES; 241 | CLANG_WARN_INFINITE_RECURSION = YES; 242 | CLANG_WARN_INT_CONVERSION = YES; 243 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 244 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 245 | CLANG_WARN_UNREACHABLE_CODE = YES; 246 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 247 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 248 | COPY_PHASE_STRIP = NO; 249 | CURRENT_PROJECT_VERSION = 1; 250 | DEBUG_INFORMATION_FORMAT = dwarf; 251 | ENABLE_STRICT_OBJC_MSGSEND = YES; 252 | ENABLE_TESTABILITY = YES; 253 | GCC_C_LANGUAGE_STANDARD = gnu99; 254 | GCC_DYNAMIC_NO_PIC = NO; 255 | GCC_NO_COMMON_BLOCKS = YES; 256 | GCC_OPTIMIZATION_LEVEL = 0; 257 | GCC_PREPROCESSOR_DEFINITIONS = ( 258 | "DEBUG=1", 259 | "$(inherited)", 260 | ); 261 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 262 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 263 | GCC_WARN_UNDECLARED_SELECTOR = YES; 264 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 265 | GCC_WARN_UNUSED_FUNCTION = YES; 266 | GCC_WARN_UNUSED_VARIABLE = YES; 267 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 268 | MTL_ENABLE_DEBUG_INFO = YES; 269 | ONLY_ACTIVE_ARCH = YES; 270 | SDKROOT = iphoneos; 271 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 272 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 273 | TARGETED_DEVICE_FAMILY = "1,2"; 274 | VERSIONING_SYSTEM = "apple-generic"; 275 | VERSION_INFO_PREFIX = ""; 276 | }; 277 | name = Debug; 278 | }; 279 | 3A0CA9FE1E5C6F9800D3B9CF /* Release */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ALWAYS_SEARCH_USER_PATHS = NO; 283 | CLANG_ANALYZER_NONNULL = YES; 284 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 285 | CLANG_CXX_LIBRARY = "libc++"; 286 | CLANG_ENABLE_MODULES = YES; 287 | CLANG_ENABLE_OBJC_ARC = YES; 288 | CLANG_WARN_BOOL_CONVERSION = YES; 289 | CLANG_WARN_CONSTANT_CONVERSION = YES; 290 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 291 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 292 | CLANG_WARN_EMPTY_BODY = YES; 293 | CLANG_WARN_ENUM_CONVERSION = YES; 294 | CLANG_WARN_INFINITE_RECURSION = YES; 295 | CLANG_WARN_INT_CONVERSION = YES; 296 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 297 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 298 | CLANG_WARN_UNREACHABLE_CODE = YES; 299 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 300 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 301 | COPY_PHASE_STRIP = NO; 302 | CURRENT_PROJECT_VERSION = 1; 303 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 304 | ENABLE_NS_ASSERTIONS = NO; 305 | ENABLE_STRICT_OBJC_MSGSEND = YES; 306 | GCC_C_LANGUAGE_STANDARD = gnu99; 307 | GCC_NO_COMMON_BLOCKS = YES; 308 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 309 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 310 | GCC_WARN_UNDECLARED_SELECTOR = YES; 311 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 312 | GCC_WARN_UNUSED_FUNCTION = YES; 313 | GCC_WARN_UNUSED_VARIABLE = YES; 314 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 315 | MTL_ENABLE_DEBUG_INFO = NO; 316 | SDKROOT = iphoneos; 317 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 318 | TARGETED_DEVICE_FAMILY = "1,2"; 319 | VALIDATE_PRODUCT = YES; 320 | VERSIONING_SYSTEM = "apple-generic"; 321 | VERSION_INFO_PREFIX = ""; 322 | }; 323 | name = Release; 324 | }; 325 | 3A0CAA001E5C6F9800D3B9CF /* Debug */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | CLANG_ENABLE_MODULES = YES; 329 | CODE_SIGN_IDENTITY = ""; 330 | DEFINES_MODULE = YES; 331 | DYLIB_COMPATIBILITY_VERSION = 1; 332 | DYLIB_CURRENT_VERSION = 1; 333 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 334 | INFOPLIST_FILE = UserDefaultsEVO/Info.plist; 335 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 336 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 337 | PRODUCT_BUNDLE_IDENTIFIER = "lacklock-gmail.com.UserDefaultsEVO"; 338 | PRODUCT_NAME = "$(TARGET_NAME)"; 339 | SKIP_INSTALL = YES; 340 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 341 | SWIFT_VERSION = 3.0; 342 | }; 343 | name = Debug; 344 | }; 345 | 3A0CAA011E5C6F9800D3B9CF /* Release */ = { 346 | isa = XCBuildConfiguration; 347 | buildSettings = { 348 | CLANG_ENABLE_MODULES = YES; 349 | CODE_SIGN_IDENTITY = ""; 350 | DEFINES_MODULE = YES; 351 | DYLIB_COMPATIBILITY_VERSION = 1; 352 | DYLIB_CURRENT_VERSION = 1; 353 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 354 | INFOPLIST_FILE = UserDefaultsEVO/Info.plist; 355 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 356 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 357 | PRODUCT_BUNDLE_IDENTIFIER = "lacklock-gmail.com.UserDefaultsEVO"; 358 | PRODUCT_NAME = "$(TARGET_NAME)"; 359 | SKIP_INSTALL = YES; 360 | SWIFT_VERSION = 3.0; 361 | }; 362 | name = Release; 363 | }; 364 | 3A0CAA031E5C6F9800D3B9CF /* Debug */ = { 365 | isa = XCBuildConfiguration; 366 | buildSettings = { 367 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 368 | INFOPLIST_FILE = UserDefaultsEVOTests/Info.plist; 369 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 370 | PRODUCT_BUNDLE_IDENTIFIER = "lacklock-gmail.com.UserDefaultsEVOTests"; 371 | PRODUCT_NAME = "$(TARGET_NAME)"; 372 | SWIFT_VERSION = 3.0; 373 | }; 374 | name = Debug; 375 | }; 376 | 3A0CAA041E5C6F9800D3B9CF /* Release */ = { 377 | isa = XCBuildConfiguration; 378 | buildSettings = { 379 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 380 | INFOPLIST_FILE = UserDefaultsEVOTests/Info.plist; 381 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 382 | PRODUCT_BUNDLE_IDENTIFIER = "lacklock-gmail.com.UserDefaultsEVOTests"; 383 | PRODUCT_NAME = "$(TARGET_NAME)"; 384 | SWIFT_VERSION = 3.0; 385 | }; 386 | name = Release; 387 | }; 388 | /* End XCBuildConfiguration section */ 389 | 390 | /* Begin XCConfigurationList section */ 391 | 3A0CA9E51E5C6F9800D3B9CF /* Build configuration list for PBXProject "UserDefaultsEVO" */ = { 392 | isa = XCConfigurationList; 393 | buildConfigurations = ( 394 | 3A0CA9FD1E5C6F9800D3B9CF /* Debug */, 395 | 3A0CA9FE1E5C6F9800D3B9CF /* Release */, 396 | ); 397 | defaultConfigurationIsVisible = 0; 398 | defaultConfigurationName = Release; 399 | }; 400 | 3A0CA9FF1E5C6F9800D3B9CF /* Build configuration list for PBXNativeTarget "UserDefaultsEVO" */ = { 401 | isa = XCConfigurationList; 402 | buildConfigurations = ( 403 | 3A0CAA001E5C6F9800D3B9CF /* Debug */, 404 | 3A0CAA011E5C6F9800D3B9CF /* Release */, 405 | ); 406 | defaultConfigurationIsVisible = 0; 407 | }; 408 | 3A0CAA021E5C6F9800D3B9CF /* Build configuration list for PBXNativeTarget "UserDefaultsEVOTests" */ = { 409 | isa = XCConfigurationList; 410 | buildConfigurations = ( 411 | 3A0CAA031E5C6F9800D3B9CF /* Debug */, 412 | 3A0CAA041E5C6F9800D3B9CF /* Release */, 413 | ); 414 | defaultConfigurationIsVisible = 0; 415 | }; 416 | /* End XCConfigurationList section */ 417 | }; 418 | rootObject = 3A0CA9E21E5C6F9800D3B9CF /* Project object */; 419 | } 420 | -------------------------------------------------------------------------------- /UserDefaultsEVO.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UserDefaultsEVO.xcodeproj/xcuserdata/zz.xcuserdatad/xcschemes/UserDefaultsEVO.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /UserDefaultsEVO.xcodeproj/xcuserdata/zz.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | UserDefaultsEVO.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 3A0CA9EA1E5C6F9800D3B9CF 16 | 17 | primary 18 | 19 | 20 | 3A0CA9F31E5C6F9800D3B9CF 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /UserDefaultsEVO/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /UserDefaultsEVO/UserDefaultsEVO.h: -------------------------------------------------------------------------------- 1 | // 2 | // UserDefaultsEVO.h 3 | // UserDefaultsEVO 4 | // 5 | // Created by 卓同学 on 2017/2/21. 6 | // Copyright © 2017年 卓同学. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for UserDefaultsEVO. 12 | FOUNDATION_EXPORT double UserDefaultsEVOVersionNumber; 13 | 14 | //! Project version string for UserDefaultsEVO. 15 | FOUNDATION_EXPORT const unsigned char UserDefaultsEVOVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /UserDefaultsEVO/UserDefaultsEVO.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UserDefaultsEVO.swift 3 | // UserDefaultsEVO 4 | // 5 | // Created by 卓同学 on 2017/2/21. 6 | // Copyright © 2017年 卓同学. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | public protocol UserDefaultSettable { 13 | var uniqueKey: String { get } 14 | } 15 | 16 | public extension UserDefaultSettable where Self: RawRepresentable, Self.RawValue == String { 17 | 18 | public func store(value: Any?){ 19 | UserDefaults.standard.set(value, forKey: uniqueKey) 20 | } 21 | public var storedValue: Any? { 22 | return UserDefaults.standard.value(forKey: uniqueKey) 23 | } 24 | public var storedString: String? { 25 | return storedValue as? String 26 | } 27 | 28 | public func store(url: URL?) { 29 | UserDefaults.standard.set(url, forKey: uniqueKey) 30 | } 31 | public var storedURL: URL? { 32 | return UserDefaults.standard.url(forKey: uniqueKey) 33 | } 34 | 35 | public func store(value: Bool) { 36 | UserDefaults.standard.set(value, forKey: uniqueKey) 37 | } 38 | public var storedBool: Bool { 39 | return UserDefaults.standard.bool(forKey: uniqueKey) 40 | } 41 | 42 | public func store(value: Int) { 43 | UserDefaults.standard.set(value, forKey: uniqueKey) 44 | } 45 | public var storedInt: Int { 46 | return UserDefaults.standard.integer(forKey: uniqueKey) 47 | } 48 | 49 | public func store(value: Double) { 50 | UserDefaults.standard.set(value, forKey: uniqueKey) 51 | } 52 | public var storedDouble: Double { 53 | return UserDefaults.standard.double(forKey: uniqueKey) 54 | } 55 | 56 | public func store(value: Float) { 57 | UserDefaults.standard.set(value, forKey: uniqueKey) 58 | } 59 | public var storedFloat: Float { 60 | return UserDefaults.standard.float(forKey: uniqueKey) 61 | } 62 | 63 | public var uniqueKey: String { 64 | return "\(Self.self).\(rawValue)" 65 | } 66 | 67 | /// removed object from standard userdefaults 68 | public func removed() { 69 | UserDefaults.standard.removeObject(forKey: uniqueKey) 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /UserDefaultsEVOTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /UserDefaultsEVOTests/UserDefaultsEVOTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UserDefaultsEVOTests.swift 3 | // UserDefaultsEVOTests 4 | // 5 | // Created by 卓同学 on 2017/2/21. 6 | // Copyright © 2017年 卓同学. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import UserDefaultsEVO 11 | 12 | extension UserDefaults { 13 | enum TestData: String,UserDefaultSettable { 14 | case name 15 | case url 16 | case bool 17 | case int 18 | case float 19 | case double 20 | } 21 | } 22 | 23 | class UserDefaultsEVOTests: XCTestCase { 24 | 25 | override func setUp() { 26 | super.setUp() 27 | } 28 | 29 | func testStringValue() { 30 | let value = "testValue" 31 | if let _ = UserDefaults.TestData.name.storedString { 32 | assertionFailure("should be nil") 33 | } 34 | UserDefaults.TestData.name.store(value: value) 35 | guard let storeValue = UserDefaults.TestData.name.storedString else { 36 | assertionFailure() 37 | return 38 | } 39 | UserDefaults.TestData.name.removed() 40 | assert(storeValue == value) 41 | } 42 | 43 | func testURL() { 44 | let value = URL(string: "lacklock@gmail.com")! 45 | if let _ = UserDefaults.TestData.url.storedURL { 46 | assertionFailure("should be nil") 47 | } 48 | UserDefaults.TestData.url.store(url: value) 49 | guard let storeValue = UserDefaults.TestData.url.storedURL else { 50 | assertionFailure() 51 | return 52 | } 53 | UserDefaults.TestData.url.removed() 54 | assert(storeValue.absoluteString == value.absoluteString) 55 | } 56 | 57 | func testBool() { 58 | let value = true 59 | if UserDefaults.TestData.bool.storedBool { 60 | assertionFailure("should be nil") 61 | } 62 | UserDefaults.TestData.bool.store(value: value) 63 | let storeValue = UserDefaults.TestData.bool.storedBool 64 | UserDefaults.TestData.bool.removed() 65 | assert(storeValue) 66 | } 67 | 68 | func testInt() { 69 | let value = 28 70 | if UserDefaults.TestData.int.storedInt != 0 { 71 | assertionFailure("should be nil") 72 | } 73 | UserDefaults.TestData.int.store(value: value) 74 | let storeValue = UserDefaults.TestData.int.storedInt 75 | UserDefaults.TestData.int.removed() 76 | assert(storeValue == value) 77 | } 78 | 79 | func testFloat() { 80 | let value: Float = 28.1 81 | if UserDefaults.TestData.float.storedInt != 0 { 82 | assertionFailure("should be nil") 83 | } 84 | UserDefaults.TestData.float.store(value: value) 85 | let storeValue = UserDefaults.TestData.float.storedFloat 86 | UserDefaults.TestData.float.removed() 87 | assert(storeValue == value) 88 | } 89 | 90 | func testDouble() { 91 | let value: Double = 28.2 92 | if UserDefaults.TestData.double.storedDouble != 0 { 93 | assertionFailure("should be nil") 94 | } 95 | UserDefaults.TestData.double.store(value: value) 96 | let storeValue = UserDefaults.TestData.double.storedDouble 97 | UserDefaults.TestData.double.removed() 98 | assert(storeValue == value) 99 | } 100 | } 101 | --------------------------------------------------------------------------------