├── .gitignore ├── LICENSE ├── Swift2Keychain.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── Swift2Keychain ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── Keychain.swift └── ViewController.swift ├── Swift2KeychainTests ├── Info.plist └── Swift2KeychainTests.swift └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Chris Hulbert 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 | 23 | -------------------------------------------------------------------------------- /Swift2Keychain.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8312AF4C1B3816FE00F1CAEE /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A2064D1B381122001C788E /* Keychain.swift */; }; 11 | 83A2062E1B38110F001C788E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A2062D1B38110F001C788E /* AppDelegate.swift */; }; 12 | 83A206301B38110F001C788E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A2062F1B38110F001C788E /* ViewController.swift */; }; 13 | 83A206331B38110F001C788E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 83A206311B38110F001C788E /* Main.storyboard */; }; 14 | 83A206351B38110F001C788E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 83A206341B38110F001C788E /* Assets.xcassets */; }; 15 | 83A206381B38110F001C788E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 83A206361B38110F001C788E /* LaunchScreen.storyboard */; }; 16 | 83A206431B381110001C788E /* Swift2KeychainTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A206421B381110001C788E /* Swift2KeychainTests.swift */; }; 17 | 83A2064E1B381122001C788E /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A2064D1B381122001C788E /* Keychain.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | 83A2063F1B381110001C788E /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = 83A206221B38110F001C788E /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = 83A206291B38110F001C788E; 26 | remoteInfo = Swift2Keychain; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | 83A2062A1B38110F001C788E /* Swift2Keychain.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Swift2Keychain.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | 83A2062D1B38110F001C788E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33 | 83A2062F1B38110F001C788E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 34 | 83A206321B38110F001C788E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 35 | 83A206341B38110F001C788E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 36 | 83A206371B38110F001C788E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 37 | 83A206391B38110F001C788E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | 83A2063E1B381110001C788E /* Swift2KeychainTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Swift2KeychainTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 83A206421B381110001C788E /* Swift2KeychainTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swift2KeychainTests.swift; sourceTree = ""; }; 40 | 83A206441B381110001C788E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | 83A2064D1B381122001C788E /* Keychain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = ""; }; 42 | /* End PBXFileReference section */ 43 | 44 | /* Begin PBXFrameworksBuildPhase section */ 45 | 83A206271B38110F001C788E /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | 83A2063B1B381110001C788E /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | 83A206211B38110F001C788E = { 63 | isa = PBXGroup; 64 | children = ( 65 | 83A2062C1B38110F001C788E /* Swift2Keychain */, 66 | 83A206411B381110001C788E /* Swift2KeychainTests */, 67 | 83A2062B1B38110F001C788E /* Products */, 68 | ); 69 | sourceTree = ""; 70 | }; 71 | 83A2062B1B38110F001C788E /* Products */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 83A2062A1B38110F001C788E /* Swift2Keychain.app */, 75 | 83A2063E1B381110001C788E /* Swift2KeychainTests.xctest */, 76 | ); 77 | name = Products; 78 | sourceTree = ""; 79 | }; 80 | 83A2062C1B38110F001C788E /* Swift2Keychain */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 83A2064D1B381122001C788E /* Keychain.swift */, 84 | 83A2062D1B38110F001C788E /* AppDelegate.swift */, 85 | 83A2062F1B38110F001C788E /* ViewController.swift */, 86 | 83A206311B38110F001C788E /* Main.storyboard */, 87 | 83A206341B38110F001C788E /* Assets.xcassets */, 88 | 83A206361B38110F001C788E /* LaunchScreen.storyboard */, 89 | 83A206391B38110F001C788E /* Info.plist */, 90 | ); 91 | path = Swift2Keychain; 92 | sourceTree = ""; 93 | }; 94 | 83A206411B381110001C788E /* Swift2KeychainTests */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 83A206421B381110001C788E /* Swift2KeychainTests.swift */, 98 | 83A206441B381110001C788E /* Info.plist */, 99 | ); 100 | path = Swift2KeychainTests; 101 | sourceTree = ""; 102 | }; 103 | /* End PBXGroup section */ 104 | 105 | /* Begin PBXNativeTarget section */ 106 | 83A206291B38110F001C788E /* Swift2Keychain */ = { 107 | isa = PBXNativeTarget; 108 | buildConfigurationList = 83A206471B381110001C788E /* Build configuration list for PBXNativeTarget "Swift2Keychain" */; 109 | buildPhases = ( 110 | 83A206261B38110F001C788E /* Sources */, 111 | 83A206271B38110F001C788E /* Frameworks */, 112 | 83A206281B38110F001C788E /* Resources */, 113 | ); 114 | buildRules = ( 115 | ); 116 | dependencies = ( 117 | ); 118 | name = Swift2Keychain; 119 | productName = Swift2Keychain; 120 | productReference = 83A2062A1B38110F001C788E /* Swift2Keychain.app */; 121 | productType = "com.apple.product-type.application"; 122 | }; 123 | 83A2063D1B381110001C788E /* Swift2KeychainTests */ = { 124 | isa = PBXNativeTarget; 125 | buildConfigurationList = 83A2064A1B381110001C788E /* Build configuration list for PBXNativeTarget "Swift2KeychainTests" */; 126 | buildPhases = ( 127 | 83A2063A1B381110001C788E /* Sources */, 128 | 83A2063B1B381110001C788E /* Frameworks */, 129 | 83A2063C1B381110001C788E /* Resources */, 130 | ); 131 | buildRules = ( 132 | ); 133 | dependencies = ( 134 | 83A206401B381110001C788E /* PBXTargetDependency */, 135 | ); 136 | name = Swift2KeychainTests; 137 | productName = Swift2KeychainTests; 138 | productReference = 83A2063E1B381110001C788E /* Swift2KeychainTests.xctest */; 139 | productType = "com.apple.product-type.bundle.unit-test"; 140 | }; 141 | /* End PBXNativeTarget section */ 142 | 143 | /* Begin PBXProject section */ 144 | 83A206221B38110F001C788E /* Project object */ = { 145 | isa = PBXProject; 146 | attributes = { 147 | LastUpgradeCheck = 0700; 148 | ORGANIZATIONNAME = "Chris Hulbert"; 149 | TargetAttributes = { 150 | 83A206291B38110F001C788E = { 151 | CreatedOnToolsVersion = 7.0; 152 | }; 153 | 83A2063D1B381110001C788E = { 154 | CreatedOnToolsVersion = 7.0; 155 | TestTargetID = 83A206291B38110F001C788E; 156 | }; 157 | }; 158 | }; 159 | buildConfigurationList = 83A206251B38110F001C788E /* Build configuration list for PBXProject "Swift2Keychain" */; 160 | compatibilityVersion = "Xcode 3.2"; 161 | developmentRegion = English; 162 | hasScannedForEncodings = 0; 163 | knownRegions = ( 164 | en, 165 | Base, 166 | ); 167 | mainGroup = 83A206211B38110F001C788E; 168 | productRefGroup = 83A2062B1B38110F001C788E /* Products */; 169 | projectDirPath = ""; 170 | projectRoot = ""; 171 | targets = ( 172 | 83A206291B38110F001C788E /* Swift2Keychain */, 173 | 83A2063D1B381110001C788E /* Swift2KeychainTests */, 174 | ); 175 | }; 176 | /* End PBXProject section */ 177 | 178 | /* Begin PBXResourcesBuildPhase section */ 179 | 83A206281B38110F001C788E /* Resources */ = { 180 | isa = PBXResourcesBuildPhase; 181 | buildActionMask = 2147483647; 182 | files = ( 183 | 83A206381B38110F001C788E /* LaunchScreen.storyboard in Resources */, 184 | 83A206351B38110F001C788E /* Assets.xcassets in Resources */, 185 | 83A206331B38110F001C788E /* Main.storyboard in Resources */, 186 | ); 187 | runOnlyForDeploymentPostprocessing = 0; 188 | }; 189 | 83A2063C1B381110001C788E /* Resources */ = { 190 | isa = PBXResourcesBuildPhase; 191 | buildActionMask = 2147483647; 192 | files = ( 193 | ); 194 | runOnlyForDeploymentPostprocessing = 0; 195 | }; 196 | /* End PBXResourcesBuildPhase section */ 197 | 198 | /* Begin PBXSourcesBuildPhase section */ 199 | 83A206261B38110F001C788E /* Sources */ = { 200 | isa = PBXSourcesBuildPhase; 201 | buildActionMask = 2147483647; 202 | files = ( 203 | 83A206301B38110F001C788E /* ViewController.swift in Sources */, 204 | 83A2062E1B38110F001C788E /* AppDelegate.swift in Sources */, 205 | 83A2064E1B381122001C788E /* Keychain.swift in Sources */, 206 | ); 207 | runOnlyForDeploymentPostprocessing = 0; 208 | }; 209 | 83A2063A1B381110001C788E /* Sources */ = { 210 | isa = PBXSourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | 83A206431B381110001C788E /* Swift2KeychainTests.swift in Sources */, 214 | 8312AF4C1B3816FE00F1CAEE /* Keychain.swift in Sources */, 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | }; 218 | /* End PBXSourcesBuildPhase section */ 219 | 220 | /* Begin PBXTargetDependency section */ 221 | 83A206401B381110001C788E /* PBXTargetDependency */ = { 222 | isa = PBXTargetDependency; 223 | target = 83A206291B38110F001C788E /* Swift2Keychain */; 224 | targetProxy = 83A2063F1B381110001C788E /* PBXContainerItemProxy */; 225 | }; 226 | /* End PBXTargetDependency section */ 227 | 228 | /* Begin PBXVariantGroup section */ 229 | 83A206311B38110F001C788E /* Main.storyboard */ = { 230 | isa = PBXVariantGroup; 231 | children = ( 232 | 83A206321B38110F001C788E /* Base */, 233 | ); 234 | name = Main.storyboard; 235 | sourceTree = ""; 236 | }; 237 | 83A206361B38110F001C788E /* LaunchScreen.storyboard */ = { 238 | isa = PBXVariantGroup; 239 | children = ( 240 | 83A206371B38110F001C788E /* Base */, 241 | ); 242 | name = LaunchScreen.storyboard; 243 | sourceTree = ""; 244 | }; 245 | /* End PBXVariantGroup section */ 246 | 247 | /* Begin XCBuildConfiguration section */ 248 | 83A206451B381110001C788E /* Debug */ = { 249 | isa = XCBuildConfiguration; 250 | buildSettings = { 251 | ALWAYS_SEARCH_USER_PATHS = NO; 252 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 253 | CLANG_CXX_LIBRARY = "libc++"; 254 | CLANG_ENABLE_MODULES = YES; 255 | CLANG_ENABLE_OBJC_ARC = YES; 256 | CLANG_WARN_BOOL_CONVERSION = YES; 257 | CLANG_WARN_CONSTANT_CONVERSION = YES; 258 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 259 | CLANG_WARN_EMPTY_BODY = YES; 260 | CLANG_WARN_ENUM_CONVERSION = YES; 261 | CLANG_WARN_INT_CONVERSION = YES; 262 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 263 | CLANG_WARN_UNREACHABLE_CODE = YES; 264 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 265 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 266 | COPY_PHASE_STRIP = NO; 267 | DEBUG_INFORMATION_FORMAT = dwarf; 268 | ENABLE_STRICT_OBJC_MSGSEND = YES; 269 | ENABLE_TESTABILITY = YES; 270 | GCC_C_LANGUAGE_STANDARD = gnu99; 271 | GCC_DYNAMIC_NO_PIC = NO; 272 | GCC_NO_COMMON_BLOCKS = YES; 273 | GCC_OPTIMIZATION_LEVEL = 0; 274 | GCC_PREPROCESSOR_DEFINITIONS = ( 275 | "DEBUG=1", 276 | "$(inherited)", 277 | ); 278 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 279 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 280 | GCC_WARN_UNDECLARED_SELECTOR = YES; 281 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 282 | GCC_WARN_UNUSED_FUNCTION = YES; 283 | GCC_WARN_UNUSED_VARIABLE = YES; 284 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 285 | MTL_ENABLE_DEBUG_INFO = YES; 286 | ONLY_ACTIVE_ARCH = YES; 287 | SDKROOT = iphoneos; 288 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 289 | }; 290 | name = Debug; 291 | }; 292 | 83A206461B381110001C788E /* Release */ = { 293 | isa = XCBuildConfiguration; 294 | buildSettings = { 295 | ALWAYS_SEARCH_USER_PATHS = NO; 296 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 297 | CLANG_CXX_LIBRARY = "libc++"; 298 | CLANG_ENABLE_MODULES = YES; 299 | CLANG_ENABLE_OBJC_ARC = YES; 300 | CLANG_WARN_BOOL_CONVERSION = YES; 301 | CLANG_WARN_CONSTANT_CONVERSION = YES; 302 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 303 | CLANG_WARN_EMPTY_BODY = YES; 304 | CLANG_WARN_ENUM_CONVERSION = YES; 305 | CLANG_WARN_INT_CONVERSION = YES; 306 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 307 | CLANG_WARN_UNREACHABLE_CODE = YES; 308 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 309 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 310 | COPY_PHASE_STRIP = NO; 311 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 312 | ENABLE_NS_ASSERTIONS = NO; 313 | ENABLE_STRICT_OBJC_MSGSEND = YES; 314 | GCC_C_LANGUAGE_STANDARD = gnu99; 315 | GCC_NO_COMMON_BLOCKS = YES; 316 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 317 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 318 | GCC_WARN_UNDECLARED_SELECTOR = YES; 319 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 320 | GCC_WARN_UNUSED_FUNCTION = YES; 321 | GCC_WARN_UNUSED_VARIABLE = YES; 322 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 323 | MTL_ENABLE_DEBUG_INFO = NO; 324 | SDKROOT = iphoneos; 325 | VALIDATE_PRODUCT = YES; 326 | }; 327 | name = Release; 328 | }; 329 | 83A206481B381110001C788E /* Debug */ = { 330 | isa = XCBuildConfiguration; 331 | buildSettings = { 332 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 333 | INFOPLIST_FILE = Swift2Keychain/Info.plist; 334 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 335 | PRODUCT_BUNDLE_IDENTIFIER = com.splinter.Swift2Keychain; 336 | PRODUCT_NAME = "$(TARGET_NAME)"; 337 | }; 338 | name = Debug; 339 | }; 340 | 83A206491B381110001C788E /* Release */ = { 341 | isa = XCBuildConfiguration; 342 | buildSettings = { 343 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 344 | INFOPLIST_FILE = Swift2Keychain/Info.plist; 345 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 346 | PRODUCT_BUNDLE_IDENTIFIER = com.splinter.Swift2Keychain; 347 | PRODUCT_NAME = "$(TARGET_NAME)"; 348 | }; 349 | name = Release; 350 | }; 351 | 83A2064B1B381110001C788E /* Debug */ = { 352 | isa = XCBuildConfiguration; 353 | buildSettings = { 354 | BUNDLE_LOADER = "$(TEST_HOST)"; 355 | INFOPLIST_FILE = Swift2KeychainTests/Info.plist; 356 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 357 | PRODUCT_BUNDLE_IDENTIFIER = com.splinter.Swift2KeychainTests; 358 | PRODUCT_NAME = "$(TARGET_NAME)"; 359 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Swift2Keychain.app/Swift2Keychain"; 360 | }; 361 | name = Debug; 362 | }; 363 | 83A2064C1B381110001C788E /* Release */ = { 364 | isa = XCBuildConfiguration; 365 | buildSettings = { 366 | BUNDLE_LOADER = "$(TEST_HOST)"; 367 | INFOPLIST_FILE = Swift2KeychainTests/Info.plist; 368 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 369 | PRODUCT_BUNDLE_IDENTIFIER = com.splinter.Swift2KeychainTests; 370 | PRODUCT_NAME = "$(TARGET_NAME)"; 371 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Swift2Keychain.app/Swift2Keychain"; 372 | }; 373 | name = Release; 374 | }; 375 | /* End XCBuildConfiguration section */ 376 | 377 | /* Begin XCConfigurationList section */ 378 | 83A206251B38110F001C788E /* Build configuration list for PBXProject "Swift2Keychain" */ = { 379 | isa = XCConfigurationList; 380 | buildConfigurations = ( 381 | 83A206451B381110001C788E /* Debug */, 382 | 83A206461B381110001C788E /* Release */, 383 | ); 384 | defaultConfigurationIsVisible = 0; 385 | defaultConfigurationName = Release; 386 | }; 387 | 83A206471B381110001C788E /* Build configuration list for PBXNativeTarget "Swift2Keychain" */ = { 388 | isa = XCConfigurationList; 389 | buildConfigurations = ( 390 | 83A206481B381110001C788E /* Debug */, 391 | 83A206491B381110001C788E /* Release */, 392 | ); 393 | defaultConfigurationIsVisible = 0; 394 | defaultConfigurationName = Release; 395 | }; 396 | 83A2064A1B381110001C788E /* Build configuration list for PBXNativeTarget "Swift2KeychainTests" */ = { 397 | isa = XCConfigurationList; 398 | buildConfigurations = ( 399 | 83A2064B1B381110001C788E /* Debug */, 400 | 83A2064C1B381110001C788E /* Release */, 401 | ); 402 | defaultConfigurationIsVisible = 0; 403 | defaultConfigurationName = Release; 404 | }; 405 | /* End XCConfigurationList section */ 406 | }; 407 | rootObject = 83A206221B38110F001C788E /* Project object */; 408 | } 409 | -------------------------------------------------------------------------------- /Swift2Keychain.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Swift2Keychain/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Swift2Keychain 4 | // 5 | // Created by Chris Hulbert on 22/06/2015. 6 | // Copyright © 2015 Chris Hulbert. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Swift2Keychain/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Swift2Keychain/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Swift2Keychain/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Swift2Keychain/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 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Swift2Keychain/Keychain.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Keychain.swift 3 | // SwiftKeychain 4 | // 5 | // Created by Chris Hulbert on 14/06/2015. 6 | // Copyright (c) 2015 Chris Hulbert. All rights reserved. 7 | // 8 | // Simple Swift 2 Keychain wrapper. 9 | 10 | import Foundation 11 | import Security 12 | 13 | struct Keychain { 14 | 15 | static func deleteAccount(account: String) { 16 | do { 17 | try SecItemWrapper.delete([ 18 | kSecClass as String: kSecClassGenericPassword, 19 | kSecAttrService as String: Constants.service, 20 | kSecAttrAccount as String: account, 21 | kSecAttrSynchronizable as String: kSecAttrSynchronizableAny, 22 | ]) 23 | } catch KeychainError.ItemNotFound { 24 | // Ignore this error. 25 | } catch let error { 26 | NSLog("deleteAccount error: \(error)") 27 | } 28 | } 29 | 30 | static func dataForAccount(account: String) -> NSData? { 31 | do { 32 | let query = [ 33 | kSecClass as String: kSecClassGenericPassword, 34 | kSecAttrService as String: Constants.service, 35 | kSecAttrAccount as String: account, 36 | kSecAttrSynchronizable as String: kSecAttrSynchronizableAny, 37 | kSecReturnData as String: kCFBooleanTrue as CFTypeRef, 38 | ] 39 | let result = try SecItemWrapper.matching(query) 40 | return result as? NSData 41 | } catch KeychainError.ItemNotFound { 42 | // Ignore this error, simply return nil. 43 | return nil 44 | } catch let error { 45 | NSLog("dataForAccount error: \(error)") 46 | return nil 47 | } 48 | } 49 | 50 | static func stringForAccount(account: String) -> String? { 51 | if let data = dataForAccount(account) { 52 | return NSString(data: data, 53 | encoding: NSUTF8StringEncoding) as? String 54 | } else { 55 | return nil 56 | } 57 | } 58 | 59 | static func setData(data: NSData, 60 | forAccount account: String, 61 | synchronizable: Bool, 62 | background: Bool) { 63 | do { 64 | // Remove the item if it already exists. 65 | // This saves having to deal with SecItemUpdate. 66 | // Reasonable people may disagree with this approach. 67 | deleteAccount(account) 68 | 69 | // Add it. 70 | try SecItemWrapper.add([ 71 | kSecClass as String: kSecClassGenericPassword, 72 | kSecAttrService as String: Constants.service, 73 | kSecAttrAccount as String: account, 74 | kSecAttrSynchronizable as String: synchronizable ? 75 | kCFBooleanTrue : kCFBooleanFalse, 76 | kSecValueData as String: data, 77 | kSecAttrAccessible as String: background ? 78 | kSecAttrAccessibleAfterFirstUnlock : 79 | kSecAttrAccessibleWhenUnlocked, 80 | ]) 81 | } catch let error { 82 | NSLog("setData error: \(error)") 83 | } 84 | } 85 | 86 | static func setString(string: String, 87 | forAccount account: String, 88 | synchronizable: Bool, 89 | background: Bool) { 90 | let data = string.dataUsingEncoding(NSUTF8StringEncoding)! 91 | setData(data, 92 | forAccount: account, 93 | synchronizable: synchronizable, 94 | background: background) 95 | } 96 | 97 | struct Constants { 98 | // FIXME: Change this to the name of your app or company! 99 | static let service = "MyService" 100 | } 101 | 102 | struct SecItemWrapper { 103 | static func matching(query: [String: AnyObject]) throws -> AnyObject? { 104 | var rawResult: Unmanaged? 105 | let rawStatus = SecItemCopyMatching(query, &rawResult) 106 | // Immediately take the retained value, so it won't leak 107 | // in case it needs to throw. 108 | let result: AnyObject? = rawResult?.takeRetainedValue() 109 | 110 | if let error = KeychainError.errorFromOSStatus(rawStatus) { 111 | throw error 112 | } 113 | return result 114 | } 115 | 116 | static func add(attributes: [String: AnyObject]) throws -> AnyObject? { 117 | var rawResult: Unmanaged? 118 | let rawStatus = SecItemAdd(attributes, &rawResult) 119 | // Immediately take the retained value, so it won't leak 120 | // in case it needs to throw. 121 | let result: AnyObject? = rawResult?.takeRetainedValue() 122 | 123 | if let error = KeychainError.errorFromOSStatus(rawStatus) { 124 | throw error 125 | } 126 | return result 127 | } 128 | 129 | static func update(query: [String: AnyObject], 130 | attributesToUpdate: [String: AnyObject]) throws { 131 | let rawStatus = SecItemUpdate(query, attributesToUpdate) 132 | if let error = KeychainError.errorFromOSStatus(rawStatus) { 133 | throw error 134 | } 135 | } 136 | 137 | static func delete(query: [String: AnyObject]) throws { 138 | let rawStatus = SecItemDelete(query) 139 | if let error = KeychainError.errorFromOSStatus(rawStatus) { 140 | throw error 141 | } 142 | } 143 | } 144 | 145 | enum KeychainError: ErrorType { 146 | case Unimplemented 147 | case Param 148 | case Allocate 149 | case NotAvailable 150 | case AuthFailed 151 | case DuplicateItem 152 | case ItemNotFound 153 | case InteractionNotAllowed 154 | case Decode 155 | case Unknown 156 | 157 | /// Returns the appropriate error for the status, or nil if it 158 | /// was successful, or Unknown for a code that doesn't match. 159 | static func errorFromOSStatus(rawStatus: OSStatus) -> KeychainError? { 160 | if rawStatus == errSecSuccess { 161 | return nil 162 | } else { 163 | // If the mapping doesn't find a match, return unknown. 164 | return mapping[rawStatus] ?? .Unknown 165 | } 166 | } 167 | 168 | static let mapping: [Int32: KeychainError] = [ 169 | errSecUnimplemented: .Unimplemented, 170 | errSecParam: .Param, 171 | errSecAllocate: .Allocate, 172 | errSecNotAvailable: .NotAvailable, 173 | errSecAuthFailed: .AuthFailed, 174 | errSecDuplicateItem: .DuplicateItem, 175 | errSecItemNotFound: .ItemNotFound, 176 | errSecInteractionNotAllowed: .InteractionNotAllowed, 177 | errSecDecode: .Decode 178 | ] 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /Swift2Keychain/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Swift2Keychain 4 | // 5 | // Created by Chris Hulbert on 22/06/2015. 6 | // Copyright © 2015 Chris Hulbert. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Swift2KeychainTests/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Swift2KeychainTests/Swift2KeychainTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Swift2KeychainTests.swift 3 | // Swift2KeychainTests 4 | // 5 | // Created by Chris Hulbert on 22/06/2015. 6 | // Copyright © 2015 Chris Hulbert. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import Swift2Keychain 11 | 12 | class Swift2KeychainTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | 17 | Keychain.deleteAccount("Account") 18 | } 19 | 20 | func testSyncBackgroundCombinations() { 21 | Keychain.setString("TestPasswordTT", forAccount: "Account", synchronizable: true, background: true) 22 | let resultTT = Keychain.stringForAccount("Account") 23 | XCTAssertEqual(resultTT!, "TestPasswordTT") 24 | 25 | Keychain.deleteAccount("Account") 26 | XCTAssertNil(Keychain.stringForAccount("Account")) 27 | 28 | 29 | Keychain.setString("TestPasswordFT", forAccount: "Account", synchronizable: false, background: true) 30 | let resultFT = Keychain.stringForAccount("Account") 31 | XCTAssertEqual(resultFT!, "TestPasswordFT") 32 | 33 | Keychain.deleteAccount("Account") 34 | XCTAssertNil(Keychain.stringForAccount("Account")) 35 | 36 | 37 | Keychain.setString("TestPasswordTF", forAccount: "Account", synchronizable: true, background: false) 38 | let resultTF = Keychain.stringForAccount("Account") 39 | XCTAssertEqual(resultTF!, "TestPasswordTF") 40 | 41 | Keychain.deleteAccount("Account") 42 | XCTAssertNil(Keychain.stringForAccount("Account")) 43 | 44 | 45 | Keychain.setString("TestPasswordFF", forAccount: "Account", synchronizable: false, background: false) 46 | let resultFF = Keychain.stringForAccount("Account") 47 | XCTAssertEqual(resultFF!, "TestPasswordFF") 48 | 49 | Keychain.deleteAccount("Account") 50 | XCTAssertNil(Keychain.stringForAccount("Account")) 51 | } 52 | 53 | func testSetAndDelete() { 54 | let blank = Keychain.stringForAccount("Account") 55 | XCTAssertNil(blank) 56 | 57 | Keychain.setString("Password", forAccount: "Account", synchronizable: false, background: false) 58 | let password = Keychain.stringForAccount("Account") 59 | XCTAssertNotNil(password) 60 | 61 | Keychain.deleteAccount("Account") 62 | let blankAgain = Keychain.stringForAccount("Account") 63 | XCTAssertNil(blankAgain) 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Swift 2 Keychain Wrapper 2 | 3 | Read about this here: [splinter.com.au/2015/06/21/swift-keychain-wrapper](http://www.splinter.com.au/2015/06/21/swift-keychain-wrapper/) 4 | --------------------------------------------------------------------------------