Skip to content

Commit 002a567

Browse files
committed
Updated all example codes in chapter-maps to Swift 2.0 (Xcode 7)
1 parent 2d4c1b5 commit 002a567

File tree

106 files changed

+786
-615
lines changed

Some content is hidden

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

106 files changed

+786
-615
lines changed

chapter-homekit/Adding Rooms to the User’s Home/Adding Rooms to the User’s Home.xcodeproj/project.pbxproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
9D022AA01982643700AA8814 /* Adding_Rooms_to_the_User_s_HomeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D022A9F1982643700AA8814 /* Adding_Rooms_to_the_User_s_HomeTests.swift */; };
1414
9D022AAB1982645200AA8814 /* ListHomesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D022AA91982645200AA8814 /* ListHomesViewController.swift */; };
1515
9D022AAC1982645200AA8814 /* AddHomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D022AAA1982645200AA8814 /* AddHomeViewController.swift */; };
16-
9D022AAF1982648E00AA8814 /* HomeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9D022AAE1982648E00AA8814 /* HomeKit.framework */; };
1716
9D022AB11982654F00AA8814 /* ListRoomsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D022AB01982654F00AA8814 /* ListRoomsTableViewController.swift */; };
1817
9D022AB31982685F00AA8814 /* AddRoomViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D022AB21982685F00AA8814 /* AddRoomViewController.swift */; };
1918
/* End PBXBuildFile section */
@@ -40,7 +39,6 @@
4039
9D022AA91982645200AA8814 /* ListHomesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListHomesViewController.swift; sourceTree = "<group>"; };
4140
9D022AAA1982645200AA8814 /* AddHomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddHomeViewController.swift; sourceTree = "<group>"; };
4241
9D022AAD1982648E00AA8814 /* Adding Rooms to the User’s Home.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Adding Rooms to the User’s Home.entitlements"; sourceTree = "<group>"; };
43-
9D022AAE1982648E00AA8814 /* HomeKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HomeKit.framework; path = System/Library/Frameworks/HomeKit.framework; sourceTree = SDKROOT; };
4442
9D022AB01982654F00AA8814 /* ListRoomsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListRoomsTableViewController.swift; sourceTree = "<group>"; };
4543
9D022AB21982685F00AA8814 /* AddRoomViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddRoomViewController.swift; sourceTree = "<group>"; };
4644
/* End PBXFileReference section */
@@ -50,7 +48,6 @@
5048
isa = PBXFrameworksBuildPhase;
5149
buildActionMask = 2147483647;
5250
files = (
53-
9D022AAF1982648E00AA8814 /* HomeKit.framework in Frameworks */,
5451
);
5552
runOnlyForDeploymentPostprocessing = 0;
5653
};
@@ -67,7 +64,6 @@
6764
9D022A7E1982643700AA8814 = {
6865
isa = PBXGroup;
6966
children = (
70-
9D022AAE1982648E00AA8814 /* HomeKit.framework */,
7167
9D022A891982643700AA8814 /* Adding Rooms to the User’s Home */,
7268
9D022A9C1982643700AA8814 /* Adding Rooms to the User’s HomeTests */,
7369
9D022A881982643700AA8814 /* Products */,
@@ -168,7 +164,8 @@
168164
9D022A7F1982643700AA8814 /* Project object */ = {
169165
isa = PBXProject;
170166
attributes = {
171-
LastUpgradeCheck = 0600;
167+
LastSwiftUpdateCheck = 0700;
168+
LastUpgradeCheck = 0700;
172169
ORGANIZATIONNAME = "Pixolity Ltd.";
173170
TargetAttributes = {
174171
9D022A861982643700AA8814 = {
@@ -287,6 +284,7 @@
287284
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
288285
COPY_PHASE_STRIP = NO;
289286
ENABLE_STRICT_OBJC_MSGSEND = YES;
287+
ENABLE_TESTABILITY = YES;
290288
GCC_C_LANGUAGE_STANDARD = gnu99;
291289
GCC_DYNAMIC_NO_PIC = NO;
292290
GCC_OPTIMIZATION_LEVEL = 0;
@@ -356,6 +354,7 @@
356354
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
357355
INFOPLIST_FILE = "Adding Rooms to the User’s Home/Info.plist";
358356
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
357+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
359358
PRODUCT_NAME = "$(TARGET_NAME)";
360359
PROVISIONING_PROFILE = "";
361360
};
@@ -371,6 +370,7 @@
371370
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
372371
INFOPLIST_FILE = "Adding Rooms to the User’s Home/Info.plist";
373372
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
373+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
374374
PRODUCT_NAME = "$(TARGET_NAME)";
375375
PROVISIONING_PROFILE = "";
376376
};
@@ -390,6 +390,7 @@
390390
);
391391
INFOPLIST_FILE = "Adding Rooms to the User’s HomeTests/Info.plist";
392392
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
393+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
393394
PRODUCT_NAME = "$(TARGET_NAME)";
394395
TEST_HOST = "$(BUNDLE_LOADER)";
395396
};
@@ -405,6 +406,7 @@
405406
);
406407
INFOPLIST_FILE = "Adding Rooms to the User’s HomeTests/Info.plist";
407408
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
409+
PRODUCT_BUNDLE_IDENTIFIER = com.pixolity.ios.cookbook.app;
408410
PRODUCT_NAME = "$(TARGET_NAME)";
409411
TEST_HOST = "$(BUNDLE_LOADER)";
410412
};
@@ -429,6 +431,7 @@
429431
9D022AA51982643700AA8814 /* Release */,
430432
);
431433
defaultConfigurationIsVisible = 0;
434+
defaultConfigurationName = Release;
432435
};
433436
9D022AA61982643700AA8814 /* Build configuration list for PBXNativeTarget "Adding Rooms to the User’s HomeTests" */ = {
434437
isa = XCConfigurationList;
@@ -437,6 +440,7 @@
437440
9D022AA81982643700AA8814 /* Release */,
438441
);
439442
defaultConfigurationIsVisible = 0;
443+
defaultConfigurationName = Release;
440444
};
441445
/* End XCConfigurationList section */
442446
};

chapter-homekit/Adding Rooms to the User’s Home/Adding Rooms to the User’s Home.xcodeproj/xcuserdata/vandadnp.xcuserdatad/xcschemes/Adding Rooms to the User’s Home.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:Adding Rooms to the User&#x2019;s Home.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 = "9D022A861982643700AA8814"
@@ -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 = "9D022A861982643700AA8814"

chapter-homekit/Adding Rooms to the User’s Home/Adding Rooms to the User’s Home/AddHomeViewController.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,22 @@ class AddHomeViewController: UIViewController {
3131

3232
@IBAction func addHome(){
3333

34-
if count(textField.text) == 0{
34+
guard let text = textField.text where text.characters.count > 0 else {
3535
UIAlertController.showAlertControllerOnHostController(self,
3636
title: "Home name", message: "Please enter the home name",
3737
buttonTitle: "OK")
3838
return
3939
}
4040

41-
homeManager.addHomeWithName(textField.text,
42-
completionHandler: {[weak self] (home: HMHome!, error: NSError!) in
43-
44-
let strongSelf = self!
41+
homeManager.addHomeWithName(text,
42+
completionHandler: {home, error in
4543

4644
if error != nil{
47-
UIAlertController.showAlertControllerOnHostController(strongSelf,
45+
UIAlertController.showAlertControllerOnHostController(self,
4846
title: "Error happened", message: "\(error)",
4947
buttonTitle: "OK")
5048
} else {
51-
strongSelf.navigationController!.popViewControllerAnimated(true)
49+
self.navigationController!.popViewControllerAnimated(true)
5250
}
5351

5452
})

chapter-homekit/Adding Rooms to the User’s Home/Adding Rooms to the User’s Home/AddRoomViewController.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,21 @@ class AddRoomViewController: UIViewController{
3232

3333
@IBAction func addRoom(){
3434

35-
if count(textField.text) == 0{
35+
guard let text = textField.text where text.characters.count > 0 else {
3636
UIAlertController.showAlertControllerOnHostController(self,
3737
title: "Room name", message: "Please enter the room name",
3838
buttonTitle: "OK")
3939
return
4040
}
4141

42-
home.addRoomWithName(textField.text, completionHandler: {[weak self]
43-
(room: HMRoom!, error: NSError!) in
44-
45-
let strongSelf = self!
42+
home.addRoomWithName(textField.text!, completionHandler: {room, error in
4643

4744
if error != nil{
48-
UIAlertController.showAlertControllerOnHostController(strongSelf,
45+
UIAlertController.showAlertControllerOnHostController(self,
4946
title: "Error happened", message: "\(error)",
5047
buttonTitle: "OK")
5148
} else {
52-
strongSelf.navigationController!.popViewControllerAnimated(true)
49+
self.navigationController!.popViewControllerAnimated(true)
5350
}
5451

5552
})

chapter-homekit/Adding Rooms to the User’s Home/Adding Rooms to the User’s Home/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-homekit/Adding Rooms to the User’s Home/Adding Rooms to the User’s Home/ListHomesViewController.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class ListHomesViewController: UITableViewController, HMHomeManagerDelegate{
7979

8080
let cell = tableView.dequeueReusableCellWithIdentifier(
8181
TableViewValues.identifier, forIndexPath: indexPath)
82-
as! UITableViewCell
82+
as UITableViewCell
8383

84-
let home = homeManager.homes[indexPath.row] as! HMHome
84+
let home = homeManager.homes[indexPath.row] as HMHome
8585

8686
cell.textLabel!.text = home.name
8787
cell.accessoryType = .DisclosureIndicator
@@ -90,8 +90,8 @@ class ListHomesViewController: UITableViewController, HMHomeManagerDelegate{
9090

9191
}
9292

93-
func homeManager(manager: HMHomeManager, didRemoveHome home: HMHome!) {
94-
println("A home has been deleted")
93+
func homeManager(manager: HMHomeManager, didRemoveHome home: HMHome) {
94+
print("A home has been deleted")
9595
}
9696

9797
func homeManagerDidUpdateHomes(manager: HMHomeManager) {
@@ -114,8 +114,8 @@ class ListHomesViewController: UITableViewController, HMHomeManagerDelegate{
114114
as! ListRoomsTableViewController
115115
controller.homeManager = homeManager
116116

117-
let home = homeManager.homes[tableView.indexPathForSelectedRow()!.row]
118-
as! HMHome
117+
let home = homeManager.homes[tableView.indexPathForSelectedRow!.row]
118+
as HMHome
119119

120120
controller.home = home
121121
}
@@ -130,14 +130,11 @@ class ListHomesViewController: UITableViewController, HMHomeManagerDelegate{
130130

131131
if editingStyle == .Delete{
132132

133-
let home = homeManager.homes[indexPath.row] as! HMHome
134-
homeManager.removeHome(home, completionHandler: {[weak self]
135-
(error: NSError!) in
136-
137-
let strongSelf = self!
133+
let home = homeManager.homes[indexPath.row] as HMHome
134+
homeManager.removeHome(home, completionHandler: {error in
138135

139136
if error != nil{
140-
UIAlertController.showAlertControllerOnHostController(strongSelf,
137+
UIAlertController.showAlertControllerOnHostController(self,
141138
title: "Error",
142139
message: "An error occurred = \(error)",
143140
buttonTitle: "OK")

chapter-homekit/Adding Rooms to the User’s Home/Adding Rooms to the User’s Home/ListRoomsTableViewController.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ class ListRoomsTableViewController: UITableViewController, HMHomeDelegate {
3939

4040
let addRoomSegueIdentifier = "addRoom"
4141

42-
func home(home: HMHome, didAddRoom room: HMRoom!) {
43-
println("Added a new room to the home")
42+
func home(home: HMHome, didAddRoom room: HMRoom) {
43+
print("Added a new room to the home")
4444
}
4545

46-
func home(home: HMHome, didRemoveRoom room: HMRoom!) {
47-
println("A room has been removed from the home")
46+
func home(home: HMHome, didRemoveRoom room: HMRoom) {
47+
print("A room has been removed from the home")
4848
}
4949

5050
override func tableView(tableView: UITableView,
@@ -58,9 +58,9 @@ class ListRoomsTableViewController: UITableViewController, HMHomeDelegate {
5858

5959
let cell = tableView.dequeueReusableCellWithIdentifier(
6060
TableViewValues.identifier, forIndexPath: indexPath)
61-
as! UITableViewCell
61+
as UITableViewCell
6262

63-
let room = home.rooms[indexPath.row] as! HMRoom
63+
let room = home.rooms[indexPath.row] as HMRoom
6464

6565
cell.textLabel!.text = room.name
6666

@@ -74,14 +74,11 @@ class ListRoomsTableViewController: UITableViewController, HMHomeDelegate {
7474

7575
if editingStyle == .Delete{
7676

77-
let room = home.rooms[indexPath.row] as! HMRoom
78-
home.removeRoom(room, completionHandler: {[weak self]
79-
(error: NSError!) in
80-
81-
let strongSelf = self!
77+
let room = home.rooms[indexPath.row] as HMRoom
78+
home.removeRoom(room, completionHandler: {error in
8279

8380
if error != nil{
84-
UIAlertController.showAlertControllerOnHostController(strongSelf,
81+
UIAlertController.showAlertControllerOnHostController(self,
8582
title: "Error",
8683
message: "An error occurred = \(error)",
8784
buttonTitle: "OK")

chapter-homekit/Adding Rooms to the User’s Home/Adding Rooms to the User’s HomeTests/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>

0 commit comments

Comments
 (0)