Skip to content

Commit 23e705a

Browse files
committed
minor tweaks to some book 2 chapter 1 examples
1 parent aa1f676 commit 23e705a

File tree

6 files changed

+37
-16
lines changed

6 files changed

+37
-16
lines changed

bk1ch12p499cancelableTimer/ch12p325NotificationLeaker/CancelableTimer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class CancelableTimer: NSObject {
1717
self.cancel()
1818
self.timer = DispatchSource.timer(queue: self.q)
1919
self.timer.scheduleRepeating(wallDeadline: DispatchWallTime.now(), interval: interval)
20+
// self.timer.scheduleRepeating(deadline: .now(), interval: 1, leeway: .milliseconds(1))
2021
self.timer.setEventHandler {
2122
if self.firsttime {
2223
self.firsttime = false

bk2ch01p006customWindowInStoryboardApp/ch14p366customWindowInStoryboardApp/AppDelegate.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ import UIKit
77
var window : UIWindow? = MyWindow() // seems this is all we need
88

99
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
10+
print("enter")
11+
print(self.window?.rootViewController)
12+
defer {
13+
print("exit") // appears _before_ symbolic breakpoint on `makeKeyAndVisible`
14+
}
1015
return true
1116
}
1217

1318

14-
}
19+
}
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11163.2" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11133"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
57
</dependencies>
68
<scenes>
79
<!--View Controller-->
810
<scene sceneID="tne-QT-ifu">
911
<objects>
10-
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
12+
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="bk2ch01p009experimenting1" customModuleProvider="target" sceneMemberID="viewController">
1113
<layoutGuides>
1214
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
1315
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
1416
</layoutGuides>
1517
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
16-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
18+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1719
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
20+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
1921
</view>
2022
</viewController>
2123
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
2224
</objects>
25+
<point key="canvasLocation" x="319" y="96"/>
2326
</scene>
2427
</scenes>
2528
</document>

bk2ch01p013bounds/ch14p371frame/AppDelegate.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension CGRect {
1111

1212
var window : UIWindow?
1313

14-
let which = 1
14+
let which = 4
1515

1616
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1717

@@ -50,6 +50,17 @@ extension CGRect {
5050

5151
v1.bounds.origin.x += 10
5252
v1.bounds.origin.y += 10
53+
54+
case 4:
55+
// showing how to center a view in its superview
56+
let v1 = UIView(frame:CGRect(113, 111, 132, 194))
57+
v1.backgroundColor = UIColor(red: 1, green: 0.4, blue: 1, alpha: 1)
58+
let v2 = UIView(frame:CGRect(0,0,20,20))
59+
v2.backgroundColor = UIColor(red: 0.5, green: 1, blue: 0, alpha: 1)
60+
mainview.addSubview(v1)
61+
v1.addSubview(v2)
62+
v2.center = v1.convert(v1.center, from:v1.superview)
63+
5364

5465
default: break
5566
}

bk2ch01p015coordinateSpace/CoordinateSpaceTest/ViewController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class ViewController: UIViewController {
77

88
@IBAction func doButton1(_ sender: UIButton) {
99
let v = sender
10-
let r = v.superview!.convert(v.frame, to: UIScreen.main().fixedCoordinateSpace)
10+
let screen = UIScreen.main().fixedCoordinateSpace
11+
let r = v.superview!.convert(v.frame, to: screen)
1112
print(r)
1213
print(v.frame)
1314
do {
@@ -18,7 +19,8 @@ class ViewController: UIViewController {
1819
}
1920
@IBAction func doButton2(_ sender: UIButton) {
2021
let v = sender
21-
let r = v.superview!.convert(v.frame, to: UIScreen.main().fixedCoordinateSpace)
22+
let screen = UIScreen.main().fixedCoordinateSpace
23+
let r = v.superview!.convert(v.frame, to: screen)
2224
print(r)
2325
print(v.frame)
2426
do {

bk2ch01p017transform/ch14p371frame/AppDelegate.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ extension CGRect {
88
}
99
}
1010

11-
1211
@UIApplicationMain class AppDelegate : UIResponder, UIApplicationDelegate {
1312

1413
var window : UIWindow?
1514

16-
let which = 6
15+
let which = 4
1716

1817
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1918

@@ -31,7 +30,7 @@ extension CGRect {
3130
mainview.addSubview(v1)
3231
v1.addSubview(v2)
3332

34-
v1.transform = CGAffineTransform(rotationAngle:45 * .pi/180.0)
33+
v1.transform = CGAffineTransform(rotationAngle:45 * .pi/180)
3534
print(v1.frame)
3635

3736
case 2:
@@ -52,7 +51,7 @@ extension CGRect {
5251
mainview.addSubview(v1)
5352
v1.addSubview(v2)
5453

55-
v2.transform = CGAffineTransform(translationX:100, y:0).rotate(45 * .pi/180.0)
54+
v2.transform = CGAffineTransform(translationX:100, y:0).rotate(45 * .pi/180)
5655

5756
case 4:
5857
let v1 = UIView(frame:CGRect(20, 111, 132, 194))
@@ -62,7 +61,7 @@ extension CGRect {
6261
mainview.addSubview(v1)
6362
v1.addSubview(v2)
6463

65-
v2.transform = CGAffineTransform(rotationAngle:45 * .pi/180.0).translateBy(x: 100, y: 0)
64+
v2.transform = CGAffineTransform(rotationAngle:45 * .pi/180).translateBy(x: 100, y: 0)
6665

6766
case 5: // same as case 4 but using concat
6867
let v1 = UIView(frame:CGRect(20, 111, 132, 194))
@@ -72,7 +71,7 @@ extension CGRect {
7271
mainview.addSubview(v1)
7372
v1.addSubview(v2)
7473

75-
let r = CGAffineTransform(rotationAngle:45 * .pi/180.0)
74+
let r = CGAffineTransform(rotationAngle:45 * .pi/180)
7675
let t = CGAffineTransform(translationX:100, y:0)
7776
v2.transform = t.concat(r) // not r.concat(t)
7877

@@ -84,7 +83,7 @@ extension CGRect {
8483
mainview.addSubview(v1)
8584
v1.addSubview(v2)
8685

87-
let r = CGAffineTransform(rotationAngle:45 * .pi/180.0)
86+
let r = CGAffineTransform(rotationAngle:45 * .pi/180)
8887
let t = CGAffineTransform(translationX:100, y:0)
8988
v2.transform = t.concat(r)
9089
v2.transform = r.invert().concat(v2.transform)

0 commit comments

Comments
 (0)