Skip to content

Commit 44b8748

Browse files
committed
Updated all code in chapter-security to Swift 2.0 (Xcode 7)
1 parent 4f7d4c3 commit 44b8748

File tree

59 files changed

+325
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+325
-213
lines changed

chapter-security/Authenticating the User with Touch ID/Authenticating the User with Touch ID.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@
153153
9D356250196B111800600CD7 /* Project object */ = {
154154
isa = PBXProject;
155155
attributes = {
156-
LastUpgradeCheck = 0600;
156+
LastSwiftUpdateCheck = 0700;
157+
LastUpgradeCheck = 0700;
157158
ORGANIZATIONNAME = "Pixolity Ltd.";
158159
TargetAttributes = {
159160
9D356257196B111800600CD7 = {
@@ -263,6 +264,7 @@
263264
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
264265
COPY_PHASE_STRIP = NO;
265266
ENABLE_STRICT_OBJC_MSGSEND = YES;
267+
ENABLE_TESTABILITY = YES;
266268
GCC_C_LANGUAGE_STANDARD = gnu99;
267269
GCC_DYNAMIC_NO_PIC = NO;
268270
GCC_OPTIMIZATION_LEVEL = 0;
@@ -329,6 +331,7 @@
329331
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
330332
INFOPLIST_FILE = "Authenticating the User with Touch ID/Info.plist";
331333
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
334+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
332335
PRODUCT_NAME = "$(TARGET_NAME)";
333336
};
334337
name = Debug;
@@ -340,6 +343,7 @@
340343
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
341344
INFOPLIST_FILE = "Authenticating the User with Touch ID/Info.plist";
342345
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
346+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
343347
PRODUCT_NAME = "$(TARGET_NAME)";
344348
};
345349
name = Release;
@@ -359,6 +363,7 @@
359363
INFOPLIST_FILE = "Authenticating the User with Touch IDTests/Info.plist";
360364
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
361365
METAL_ENABLE_DEBUG_INFO = YES;
366+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
362367
PRODUCT_NAME = "$(TARGET_NAME)";
363368
TEST_HOST = "$(BUNDLE_LOADER)";
364369
};
@@ -375,6 +380,7 @@
375380
INFOPLIST_FILE = "Authenticating the User with Touch IDTests/Info.plist";
376381
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
377382
METAL_ENABLE_DEBUG_INFO = NO;
383+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
378384
PRODUCT_NAME = "$(TARGET_NAME)";
379385
TEST_HOST = "$(BUNDLE_LOADER)";
380386
};
@@ -399,6 +405,7 @@
399405
9D356276196B111800600CD7 /* Release */,
400406
);
401407
defaultConfigurationIsVisible = 0;
408+
defaultConfigurationName = Release;
402409
};
403410
9D356277196B111800600CD7 /* Build configuration list for PBXNativeTarget "Authenticating the User with Touch IDTests" */ = {
404411
isa = XCConfigurationList;
@@ -407,6 +414,7 @@
407414
9D356279196B111800600CD7 /* Release */,
408415
);
409416
defaultConfigurationIsVisible = 0;
417+
defaultConfigurationName = Release;
410418
};
411419
/* End XCConfigurationList section */
412420
};

chapter-security/Authenticating the User with Touch ID/Authenticating the User with Touch ID.xcodeproj/xcuserdata/vandadnp.xcuserdatad/xcschemes/Authenticating the User with Touch ID.xcscheme

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0600"
3+
LastUpgradeVersion = "0700"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -48,6 +48,8 @@
4848
ReferencedContainer = "container:Authenticating the User with Touch ID.xcodeproj">
4949
</BuildableReference>
5050
</MacroExpansion>
51+
<AdditionalOptions>
52+
</AdditionalOptions>
5153
</TestAction>
5254
<LaunchAction
5355
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
@@ -57,8 +59,10 @@
5759
buildConfiguration = "Debug"
5860
ignoresPersistentStateOnLaunch = "NO"
5961
debugDocumentVersioning = "YES"
62+
debugServiceExtension = "internal"
6063
allowLocationSimulation = "YES">
61-
<BuildableProductRunnable>
64+
<BuildableProductRunnable
65+
runnableDebuggingMode = "0">
6266
<BuildableReference
6367
BuildableIdentifier = "primary"
6468
BlueprintIdentifier = "9D356257196B111800600CD7"
@@ -76,7 +80,8 @@
7680
useCustomWorkingDirectory = "NO"
7781
buildConfiguration = "Release"
7882
debugDocumentVersioning = "YES">
79-
<BuildableProductRunnable>
83+
<BuildableProductRunnable
84+
runnableDebuggingMode = "0">
8085
<BuildableReference
8186
BuildableIdentifier = "primary"
8287
BlueprintIdentifier = "9D356257196B111800600CD7"

chapter-security/Authenticating the User with Touch ID/Authenticating the User with Touch ID/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>${EXECUTABLE_NAME}</string>
99
<key>CFBundleIdentifier</key>
10-
<string>com.pixolity.ios.cookbook.app</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>

chapter-security/Authenticating the User with Touch ID/Authenticating the User with Touch ID/ViewController.swift

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ class ViewController: UIViewController {
3232
@IBAction func checkTouchIdAvailability(sender: AnyObject) {
3333

3434
let context = LAContext()
35-
var error: NSError?
3635

37-
let isTouchIdAvailable = context.canEvaluatePolicy(
38-
.DeviceOwnerAuthenticationWithBiometrics,
39-
error: &error)
40-
41-
buttonUseTouchId.enabled = isTouchIdAvailable
42-
43-
/* Touch ID is not available */
44-
if isTouchIdAvailable == false{
36+
do {
37+
try context.canEvaluatePolicy(
38+
.DeviceOwnerAuthenticationWithBiometrics)
39+
40+
buttonUseTouchId.enabled = true
4541

4642
let alertController = UIAlertController(title: "Touch ID",
4743
message: "Touch ID is not available",
@@ -53,6 +49,8 @@ class ViewController: UIViewController {
5349

5450
presentViewController(alertController, animated: true, completion: nil)
5551

52+
} catch {
53+
buttonUseTouchId.enabled = false
5654
}
5755

5856
}
@@ -61,12 +59,11 @@ class ViewController: UIViewController {
6159
/* We will code this soon */
6260

6361
let context = LAContext()
64-
var error: NSError?
6562
let reason = "Please authenticate with Touch ID " +
6663
"to access your private information"
6764

6865
context.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics,
69-
localizedReason: reason, reply: {(success: Bool, error: NSError!) in
66+
localizedReason: reason, reply: {success, error in
7067

7168
if success{
7269
/* The user was successfully authenticated */

chapter-security/Authenticating the User with Touch ID/Authenticating the User with Touch IDTests/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>${EXECUTABLE_NAME}</string>
99
<key>CFBundleIdentifier</key>
10-
<string>com.pixolity.ios.cookbook.app</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>

chapter-security/Deleting Exiting Values in the Keychain/Deleting Exiting Values in the Keychain.xcodeproj/project.pbxproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@
155155
9D356146196AF60A00600CD7 /* Project object */ = {
156156
isa = PBXProject;
157157
attributes = {
158-
LastUpgradeCheck = 0600;
158+
LastSwiftUpdateCheck = 0700;
159+
LastUpgradeCheck = 0700;
159160
ORGANIZATIONNAME = "Pixolity Ltd.";
160161
TargetAttributes = {
161162
9D35614D196AF60A00600CD7 = {
@@ -271,6 +272,7 @@
271272
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
272273
COPY_PHASE_STRIP = NO;
273274
ENABLE_STRICT_OBJC_MSGSEND = YES;
275+
ENABLE_TESTABILITY = YES;
274276
GCC_C_LANGUAGE_STANDARD = gnu99;
275277
GCC_DYNAMIC_NO_PIC = NO;
276278
GCC_OPTIMIZATION_LEVEL = 0;
@@ -340,6 +342,7 @@
340342
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Vandad Nahavandipoor (J54K6K24Z3)";
341343
INFOPLIST_FILE = "Deleting Exiting Values in the Keychain/Info.plist";
342344
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
345+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
343346
PRODUCT_NAME = "$(TARGET_NAME)";
344347
PROVISIONING_PROFILE = "16B110EE-4B5A-4B6C-9D22-9F18B7FFC1FA";
345348
};
@@ -355,6 +358,7 @@
355358
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Vandad Nahavandipoor (J54K6K24Z3)";
356359
INFOPLIST_FILE = "Deleting Exiting Values in the Keychain/Info.plist";
357360
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
361+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
358362
PRODUCT_NAME = "$(TARGET_NAME)";
359363
PROVISIONING_PROFILE = "16B110EE-4B5A-4B6C-9D22-9F18B7FFC1FA";
360364
};
@@ -375,6 +379,7 @@
375379
INFOPLIST_FILE = "Deleting Exiting Values in the KeychainTests/Info.plist";
376380
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
377381
METAL_ENABLE_DEBUG_INFO = YES;
382+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
378383
PRODUCT_NAME = "$(TARGET_NAME)";
379384
TEST_HOST = "$(BUNDLE_LOADER)";
380385
};
@@ -391,6 +396,7 @@
391396
INFOPLIST_FILE = "Deleting Exiting Values in the KeychainTests/Info.plist";
392397
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
393398
METAL_ENABLE_DEBUG_INFO = NO;
399+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
394400
PRODUCT_NAME = "$(TARGET_NAME)";
395401
TEST_HOST = "$(BUNDLE_LOADER)";
396402
};

chapter-security/Deleting Exiting Values in the Keychain/Deleting Exiting Values in the Keychain.xcodeproj/xcuserdata/vandadnp.xcuserdatad/xcschemes/Deleting Exiting Values in the Keychain.xcscheme

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0600"
3+
LastUpgradeVersion = "0700"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -48,6 +48,8 @@
4848
ReferencedContainer = "container:Deleting Exiting Values in the Keychain.xcodeproj">
4949
</BuildableReference>
5050
</MacroExpansion>
51+
<AdditionalOptions>
52+
</AdditionalOptions>
5153
</TestAction>
5254
<LaunchAction
5355
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
@@ -57,8 +59,10 @@
5759
buildConfiguration = "Debug"
5860
ignoresPersistentStateOnLaunch = "NO"
5961
debugDocumentVersioning = "YES"
62+
debugServiceExtension = "internal"
6063
allowLocationSimulation = "YES">
61-
<BuildableProductRunnable>
64+
<BuildableProductRunnable
65+
runnableDebuggingMode = "0">
6266
<BuildableReference
6367
BuildableIdentifier = "primary"
6468
BlueprintIdentifier = "9D35614D196AF60A00600CD7"
@@ -76,7 +80,8 @@
7680
useCustomWorkingDirectory = "NO"
7781
buildConfiguration = "Release"
7882
debugDocumentVersioning = "YES">
79-
<BuildableProductRunnable>
83+
<BuildableProductRunnable
84+
runnableDebuggingMode = "0">
8085
<BuildableReference
8186
BuildableIdentifier = "primary"
8287
BlueprintIdentifier = "9D35614D196AF60A00600CD7"

chapter-security/Deleting Exiting Values in the Keychain/Deleting Exiting Values in the Keychain/AppDelegate.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3636
let service = NSBundle.mainBundle().bundleIdentifier!
3737

3838
let query = [
39-
kSecClass as! String :
40-
kSecClassGenericPassword as! String,
39+
kSecClass as String :
40+
kSecClassGenericPassword as String,
4141

42-
kSecAttrService as! String : service,
43-
kSecAttrAccount as! String : keyToSearchFor,
42+
kSecAttrService as String : service,
43+
kSecAttrAccount as String : keyToSearchFor,
4444
]
4545

4646

@@ -51,13 +51,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5151

5252
let deleted = Int(SecItemDelete(query))
5353
if deleted == Int(errSecSuccess){
54-
println("Successfully deleted the item")
54+
print("Successfully deleted the item")
5555
} else {
56-
println("Failed to delete the item")
56+
print("Failed to delete the item")
5757
}
5858

5959
} else {
60-
println("Error happened with code: \(foundExisting)")
60+
print("Error happened with code: \(foundExisting)")
6161
}
6262

6363
return true

0 commit comments

Comments
 (0)