Skip to content

Commit 91cbc1e

Browse files
committed
update for Swift 1.2, Xcode 6.3
1 parent 08c9780 commit 91cbc1e

File tree

45 files changed

+117
-122
lines changed

Some content is hidden

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

45 files changed

+117
-122
lines changed

bk2ch06p236manualViewController/ch19p575manualViewController/RootViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import UIKit
44

55
class RootViewController: UIViewController {
66

7-
let which = 2
7+
let which = 1
88

99
override func loadView() {
1010
let v = UIView()

bk2ch06p239nibViewController/ch19p575manualViewController/AppDelegate.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ class AppDelegate : UIResponder, UIApplicationDelegate {
99

1010
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
1111

12-
let theRVC = RootViewController(nibName:"MyNib", bundle:nil) // explicit nib name
12+
// demonstrating that the eponymous .xib file is _not_ found automatically:
1313

14-
// in iOS 3, 4, 5, 6, and 7,
15-
// if the nib is called "RootView.xib" or "RootViewController.xib",
16-
// you can pass nil as the nibName here (or call init() with no args)
17-
// but in iOS 8 (starting with seed 5?) this feature is gone for "RootViewController.xib"
18-
// ... but it does still work for "RootView.xib"!
19-
// I don't know if that's a momentary bug or what, but...
20-
// (In one way, it feels deliberate, since RootViewController is a dumb name for xib file!)
21-
// since I can't rely on it, however, I'm going to stop relying on it from here on in
22-
// so it's going to be explicit nib names from now on, I guess
14+
let theRVC = RootViewController()
15+
16+
// the empty white window proves that our nib is not loading
2317

2418
self.window!.rootViewController = theRVC
2519

bk2ch06p239nibViewController/ch19p575manualViewController/MyNib.xib renamed to bk2ch06p239nibViewController/ch19p575manualViewController/RootViewController.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6249" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6243"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
55
</dependencies>
66
<objects>
77
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RootViewController">

bk2ch06p239nibViewController/ch19p579nibViewController.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
C9AFFBBD17C27B8C00C3BAB0 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9AFFBBC17C27B8C00C3BAB0 /* CoreGraphics.framework */; };
1414
C9AFFBBF17C27B8C00C3BAB0 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9AFFBBE17C27B8C00C3BAB0 /* UIKit.framework */; };
1515
C9AFFBCD17C27B8C00C3BAB0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C9AFFBCC17C27B8C00C3BAB0 /* Images.xcassets */; };
16-
C9AFFBED17C2850200C3BAB0 /* MyNib.xib in Resources */ = {isa = PBXBuildFile; fileRef = C9AFFBEC17C2850200C3BAB0 /* MyNib.xib */; };
16+
C9AFFBED17C2850200C3BAB0 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C9AFFBEC17C2850200C3BAB0 /* RootViewController.xib */; };
1717
/* End PBXBuildFile section */
1818

1919
/* Begin PBXFileReference section */
@@ -26,7 +26,7 @@
2626
C9AFFBC217C27B8C00C3BAB0 /* ch19p579nibViewController-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ch19p579nibViewController-Info.plist"; sourceTree = "<group>"; };
2727
C9AFFBCC17C27B8C00C3BAB0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
2828
C9AFFBD317C27B8C00C3BAB0 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
29-
C9AFFBEC17C2850200C3BAB0 /* MyNib.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MyNib.xib; sourceTree = "<group>"; };
29+
C9AFFBEC17C2850200C3BAB0 /* RootViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RootViewController.xib; sourceTree = "<group>"; };
3030
/* End PBXFileReference section */
3131

3232
/* Begin PBXFrameworksBuildPhase section */
@@ -76,7 +76,7 @@
7676
children = (
7777
321A94111974434700B88F5B /* AppDelegate.swift */,
7878
321A94131974436300B88F5B /* RootViewController.swift */,
79-
C9AFFBEC17C2850200C3BAB0 /* MyNib.xib */,
79+
C9AFFBEC17C2850200C3BAB0 /* RootViewController.xib */,
8080
C9AFFBCC17C27B8C00C3BAB0 /* Images.xcassets */,
8181
C9AFFBC117C27B8C00C3BAB0 /* Supporting Files */,
8282
);
@@ -142,7 +142,7 @@
142142
isa = PBXResourcesBuildPhase;
143143
buildActionMask = 2147483647;
144144
files = (
145-
C9AFFBED17C2850200C3BAB0 /* MyNib.xib in Resources */,
145+
C9AFFBED17C2850200C3BAB0 /* RootViewController.xib in Resources */,
146146
C9AFFBCD17C27B8C00C3BAB0 /* Images.xcassets in Resources */,
147147
);
148148
runOnlyForDeploymentPostprocessing = 0;

bk2ch06p239nibViewControllerWorkaround3/ch19p575manualViewController/RootViewController.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import UIKit
33

44
class RootViewController : UIViewController {
5-
required init(coder: NSCoder) {
6-
fatalError("NSCoding not supported")
7-
}
8-
override init() {
5+
init() {
96
super.init(nibName:"RootViewController", bundle:nil)
107
}
8+
9+
required init(coder aDecoder: NSCoder) {
10+
fatalError("init(coder:) has not been implemented")
11+
}
1112

1213
}

bk2ch06p239nibViewControllerWorkaround5/ch19p575manualViewController/AppDelegate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class AppDelegate : UIResponder, UIApplicationDelegate {
99

1010
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
1111

12+
// workaround 5, my favorite: override the `nibName` getter
13+
1214
let theRVC = RootViewController()
1315

1416
self.window!.rootViewController = theRVC

bk2ch06p242nibInstantiatedViewController/ch19p583nibInstantiatedViewController/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class AppDelegate : UIResponder, UIApplicationDelegate {
1212

1313
let arr = UINib(
1414
nibName: "Main", bundle: nil).instantiateWithOwner(
15-
nil, options: nil) as [UIViewController]
15+
nil, options: nil) as! [UIViewController]
1616
self.window!.rootViewController = arr[0]
1717

1818
self.window!.backgroundColor = UIColor.whiteColor()

bk2ch06p250sizeChangeTest/SizeChangeTest/ViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import UIKit
1717
class ViewController: UIViewController {
1818

1919
@IBAction func doButton(sender: AnyObject) {
20+
println(self.view.bounds.size)
2021
let nav = self.navigationController!
2122
nav.navigationBarHidden = !nav.navigationBarHidden
2223
delay(1) {
@@ -26,7 +27,7 @@ class ViewController: UIViewController {
2627
}
2728

2829
override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
29-
println("will rotate") // not called if viewWillTransitionToSize is implement
30+
println("will rotate") // not called if viewWillTransitionToSize is implemented
3031
}
3132

3233
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {

bk2ch06p253orientationsPermitted/ch19p590orientationsPermitted/ViewController.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ class ViewController : UIViewController {
66

77
// how to override the application's list of possible orientations
88
// at the view controller level
9-
10-
// something weird is going on in the Swift version of this
11-
// why does supportedInterfaceOrientations() was to return Int?
12-
// should be UInt...
13-
14-
// And then, how are we supposed to obtain the necessary Int?
15-
// Apparently you have to call rawValue, which is annoying
169

1710
override func supportedInterfaceOrientations() -> Int {
1811

@@ -21,7 +14,9 @@ class ViewController : UIViewController {
2114
let result = UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)
2215
println(result)
2316

17+
// uncomment next line in order to crash
2418
// return UIInterfaceOrientation.Portrait.rawValue // crash!
19+
2520
// ha ha, you didn't read the docs
2621
// you don't return an orientation; you return an orientation *mask*
2722
// (UIInterfaceOrientationMask)
@@ -33,6 +28,8 @@ class ViewController : UIViewController {
3328

3429
println("supported") // called 10 times at launch! WTF?
3530
// and then 6 more times if you tap on the interface!
31+
// okay, in my latest test it's only 5 times at launch
32+
// I guess that's, uh, better...
3633

3734
return Int(UIInterfaceOrientationMask.Portrait.rawValue) // gag me with a spoon
3835
}

bk2ch06p253orientationsPermitted2/ch19p590orientationsPermitted/AppDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class AppDelegate : UIResponder, UIApplicationDelegate {
1010
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1111
return true
1212
}
13-
14-
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) -> Int {
13+
14+
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
1515
println("supported") // whoa
1616

1717
// uncomment next line to get a different answer...

0 commit comments

Comments
 (0)