Skip to content

Commit 1de777b

Browse files
committed
minor tweaks up thru chapter 5
1 parent 8eb159a commit 1de777b

File tree

8 files changed

+69
-10
lines changed

8 files changed

+69
-10
lines changed

bk1ch05p230switch/bk1ch05p230switch/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class ViewController: UIViewController, UIBarPositioningDelegate {
213213
}
214214

215215
switch err {
216-
case .number(1..<Int.max):
216+
case .number(1...Int.max):
217217
print("It's a positive error number")
218218
case .number(Int.min...(-1)):
219219
print("It's a negative error number")

bk1ch05p239loops/bk1ch05p239loops/ViewController.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ class ViewController: UIViewController {
176176

177177
do {
178178
let seq = sequence(first:1) {$0 >= 10 ? nil : $0 + 1}
179-
print(Array(seq))
180179
for i in seq {
181-
print(i)
180+
print(i) // 1,2,3,4,5,6,7,8,9,10
181+
}
182+
let seq2 = sequence(first:1) {$0 + 1}
183+
for i in seq2.prefix(5) {
184+
print(i) // 1,2,3,4,5
182185
}
183-
print(Array(seq.prefix(5)))
184186
}
185187

186188
do {
@@ -198,7 +200,9 @@ class ViewController: UIViewController {
198200
pair = (pair.1,n)
199201
return n
200202
}
201-
print(Array(fib.prefix(10)))
203+
for i in fib.prefix(10) {
204+
print(i)
205+
}
202206
// i.e. the first 10 elements of the fibonacci sequence
203207
}
204208

bk1ch05p240error/bk1ch05p241error.xcodeproj/project.pbxproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
32F8A8B81B385DBA0042B53B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32F8A8B61B385DBA0042B53B /* Main.storyboard */; };
1414
32F8A8BA1B385DBA0042B53B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32F8A8B91B385DBA0042B53B /* Assets.xcassets */; };
1515
32F8A8BD1B385DBA0042B53B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32F8A8BB1B385DBA0042B53B /* LaunchScreen.storyboard */; };
16+
81668A631D315F1300EC7B6E /* Thing.m in Sources */ = {isa = PBXBuildFile; fileRef = 81668A621D315F1300EC7B6E /* Thing.m */; };
1617
/* End PBXBuildFile section */
1718

1819
/* Begin PBXFileReference section */
@@ -24,6 +25,9 @@
2425
32F8A8B91B385DBA0042B53B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2526
32F8A8BC1B385DBA0042B53B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2627
32F8A8BE1B385DBA0042B53B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
28+
81668A601D315F1300EC7B6E /* bk1ch05p241error-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "bk1ch05p241error-Bridging-Header.h"; sourceTree = "<group>"; };
29+
81668A611D315F1300EC7B6E /* Thing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Thing.h; sourceTree = "<group>"; };
30+
81668A621D315F1300EC7B6E /* Thing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Thing.m; sourceTree = "<group>"; };
2731
/* End PBXFileReference section */
2832

2933
/* Begin PBXFrameworksBuildPhase section */
@@ -58,11 +62,14 @@
5862
children = (
5963
32F8A8B21B385DBA0042B53B /* AppDelegate.swift */,
6064
32F8A8B41B385DBA0042B53B /* ViewController.swift */,
65+
81668A611D315F1300EC7B6E /* Thing.h */,
66+
81668A621D315F1300EC7B6E /* Thing.m */,
6167
3269B3121B8D39B3009950F2 /* testing.txt */,
6268
32F8A8B61B385DBA0042B53B /* Main.storyboard */,
6369
32F8A8B91B385DBA0042B53B /* Assets.xcassets */,
6470
32F8A8BB1B385DBA0042B53B /* LaunchScreen.storyboard */,
6571
32F8A8BE1B385DBA0042B53B /* Info.plist */,
72+
81668A601D315F1300EC7B6E /* bk1ch05p241error-Bridging-Header.h */,
6673
);
6774
path = bk1ch05p241error;
6875
sourceTree = "<group>";
@@ -139,6 +146,7 @@
139146
isa = PBXSourcesBuildPhase;
140147
buildActionMask = 2147483647;
141148
files = (
149+
81668A631D315F1300EC7B6E /* Thing.m in Sources */,
142150
32F8A8B51B385DBA0042B53B /* ViewController.swift in Sources */,
143151
32F8A8B31B385DBA0042B53B /* AppDelegate.swift in Sources */,
144152
);
@@ -251,10 +259,13 @@
251259
isa = XCBuildConfiguration;
252260
buildSettings = {
253261
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
262+
CLANG_ENABLE_MODULES = YES;
254263
INFOPLIST_FILE = bk1ch05p241error/Info.plist;
255264
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
256265
PRODUCT_BUNDLE_IDENTIFIER = com.neuburg.matt.bk1ch05p241error;
257266
PRODUCT_NAME = "$(TARGET_NAME)";
267+
SWIFT_OBJC_BRIDGING_HEADER = "bk1ch05p241error/bk1ch05p241error-Bridging-Header.h";
268+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
258269
SWIFT_VERSION = 3.0;
259270
};
260271
name = Debug;
@@ -263,10 +274,12 @@
263274
isa = XCBuildConfiguration;
264275
buildSettings = {
265276
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
277+
CLANG_ENABLE_MODULES = YES;
266278
INFOPLIST_FILE = bk1ch05p241error/Info.plist;
267279
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
268280
PRODUCT_BUNDLE_IDENTIFIER = com.neuburg.matt.bk1ch05p241error;
269281
PRODUCT_NAME = "$(TARGET_NAME)";
282+
SWIFT_OBJC_BRIDGING_HEADER = "bk1ch05p241error/bk1ch05p241error-Bridging-Header.h";
270283
SWIFT_VERSION = 3.0;
271284
};
272285
name = Release;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
#import <Foundation/Foundation.h>
4+
5+
@interface Thing : NSObject
6+
7+
@end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
3+
#import "Thing.h"
4+
5+
@implementation Thing
6+
7+
- (void) dummy {
8+
9+
NSString* f = @"";
10+
11+
NSError* err;
12+
NSString* s =
13+
[[NSString alloc] initWithContentsOfFile:f
14+
encoding:NSUTF8StringEncoding
15+
error:&err];
16+
if (s == nil) {
17+
NSLog(@"%@", err);
18+
}
19+
20+
21+
22+
}
23+
24+
@end

bk1ch05p240error/bk1ch05p241error/ViewController.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ enum MySecondError : ErrorProtocol {
1616
struct SomeStruct : ErrorProtocol {
1717

1818
}
19-
struct SomeClass : ErrorProtocol {
19+
class SomeClass : ErrorProtocol {
2020

2121
}
2222

23+
class MyClassyError : ErrorProtocol {
24+
init() {
25+
// self._code = 666 // nope, it's immutable
26+
}
27+
}
28+
29+
2330
struct SomeStruct2 : ErrorProtocol {
2431
let name : String
2532
static var someError: SomeStruct2 { return SomeStruct2(name:"howdy") }
@@ -94,7 +101,7 @@ class ViewController: UIViewController {
94101
print(err3._domain)
95102
print(err3._code)
96103
print(err3 as NSError)
97-
104+
98105

99106
}
100107

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+

bk1ch05p254memoryManagement/bk1ch05p254memoryManagement/ViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class MyDropBounceAndRollBehavior : UIDynamicBehavior {
2121
self.v = v
2222
super.init()
2323
}
24-
override func willMove(to anim: UIDynamicAnimator!) {
25-
if anim == nil { return }
24+
override func willMove(to anim: UIDynamicAnimator?) {
25+
guard let anim = anim else { return }
2626
let sup = self.v.superview!
2727
let grav = UIGravityBehavior()
2828
grav.action = {
@@ -45,7 +45,7 @@ class SecondViewController : UIViewController {
4545
// ...
4646
}
4747
protocol SecondViewControllerDelegate : class {
48-
func acceptData(data:AnyObject!)
48+
func accept(data:AnyObject!)
4949
}
5050

5151

0 commit comments

Comments
 (0)