Skip to content

Commit 5e7a5a4

Browse files
committed
mostly updating chapter 4 examples; also, remove lazy var type declarations that are no longer needed, and use #keyPath in more places
1 parent 8a22b6b commit 5e7a5a4

File tree

55 files changed

+2087
-138
lines changed

Some content is hidden

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

55 files changed

+2087
-138
lines changed

bk1ch03p075lazy/bk1ch03p075lazy/ViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class MyClass {
99
}
1010

1111
class MyView : UIView {
12-
lazy var arrow : UIImage = self.arrowImage()
12+
// lazy var arrow : UIImage = self.arrowImage()
13+
// explicit type not required if not using define-and-call
14+
lazy var arrow = self.arrowImage()
1315
func arrowImage () -> UIImage {
1416
// ... big image-generating code goes here ...
1517
return UIImage() // stub

bk1ch04p121properties/bk1ch04p121properties/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Moi2 {
2020
class Moi3 {
2121
let first = "Matt"
2222
let last = "Neuburg"
23-
lazy var whole : String = self.first + " " + self.last
23+
lazy var whole = self.first + " " + self.last // can omit self here
2424
}
2525

2626
class Moi4 {
@@ -44,7 +44,7 @@ class Moi5 {
4444
class Moi6 {
4545
let first = "Matt"
4646
let last = "Neuburg"
47-
lazy var whole : String = self.wholeName()
47+
lazy var whole = self.wholeName()
4848
func wholeName() -> String {
4949
return self.first + " " + self.last
5050
}

bk1ch04p204arrays/bk1ch04p204collections/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ class ViewController: UIViewController {
512512
}
513513

514514
do {
515-
let anim = CAKeyframeAnimation(keyPath:"position") // dummy
515+
let anim = CAKeyframeAnimation(keyPath:#keyPath(CALayer.position)) // dummy
516516
let (oldP,p1,p2,newP) = (CGPoint.zero,CGPoint.zero,CGPoint.zero,CGPoint.zero) // dummy
517517
let points = [oldP,p1,p2,newP]
518518
anim.values = points.map {NSValue(cgPoint:$0)}

bk1ch10p428foundationClasses/bk1ch10p428foundationClasses/ViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,15 @@ class ViewController: UIViewController {
228228
do {
229229
/*
230230
let goal = CGPoint.zero // dummy
231-
let ba = CABasicAnimation(keyPath:"position")
231+
let ba = CABasicAnimation(keyPath:#keyPath(CALayer.position))
232232
ba.duration = 10
233233
ba.fromValue = NSValue(cgPoint:self.oldButtonCenter)
234234
ba.toValue = NSValue(cgPoint:goal)
235235
self.button.layer.add(ba, forKey:nil)
236236
*/
237237
// but that is no longer needed! now we can say:
238238
let goal = CGPoint.zero // dummy
239-
let ba = CABasicAnimation(keyPath:"position")
239+
let ba = CABasicAnimation(keyPath:#keyPath(CALayer.position))
240240
ba.duration = 10
241241
ba.fromValue = self.oldButtonCenter
242242
ba.toValue = goal
@@ -248,7 +248,7 @@ class ViewController: UIViewController {
248248

249249
// this is no longer needed either
250250
do {
251-
let anim = CAKeyframeAnimation(keyPath:"position") // dummy
251+
let anim = CAKeyframeAnimation(keyPath:#keyPath(CALayer.position)) // dummy
252252
let (oldP,p1,p2,newP) = (CGPoint.zero,CGPoint.zero,CGPoint.zero,CGPoint.zero) // dummy
253253
anim.values = [oldP,p1,p2,newP].map {NSValue(cgPoint:$0)}
254254
}

bk2ch01p031constraints/ch14p382autoresizing/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class ViewController: UIViewController {
115115
// okay, that's boring...
116116
// let's write our own Swift NSDictionaryOfVariableBindings substitute (sort of)
117117
let d = dictionaryOfNames(v1,v2,v3)
118+
// could write activate(c + c + c) instead
118119
NSLayoutConstraint.activate([
119120
NSLayoutConstraint.constraints(withVisualFormat:
120121
"H:|[v2]|", metrics: nil, views: d),
Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 48;
7+
objects = {
8+
9+
/* Begin PBXBuildFile section */
10+
81DB95E11F49F72A005550D2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81DB95E01F49F72A005550D2 /* AppDelegate.swift */; };
11+
81DB95E31F49F72A005550D2 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81DB95E21F49F72A005550D2 /* ViewController.swift */; };
12+
81DB95E61F49F72A005550D2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81DB95E41F49F72A005550D2 /* Main.storyboard */; };
13+
81DB95E81F49F72A005550D2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 81DB95E71F49F72A005550D2 /* Assets.xcassets */; };
14+
81DB95EB1F49F72A005550D2 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81DB95E91F49F72A005550D2 /* LaunchScreen.storyboard */; };
15+
/* End PBXBuildFile section */
16+
17+
/* Begin PBXFileReference section */
18+
81DB95DD1F49F72A005550D2 /* PresentationLayerTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PresentationLayerTest.app; sourceTree = BUILT_PRODUCTS_DIR; };
19+
81DB95E01F49F72A005550D2 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
20+
81DB95E21F49F72A005550D2 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
21+
81DB95E51F49F72A005550D2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
22+
81DB95E71F49F72A005550D2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
23+
81DB95EA1F49F72A005550D2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
24+
81DB95EC1F49F72A005550D2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
25+
/* End PBXFileReference section */
26+
27+
/* Begin PBXFrameworksBuildPhase section */
28+
81DB95DA1F49F72A005550D2 /* Frameworks */ = {
29+
isa = PBXFrameworksBuildPhase;
30+
buildActionMask = 2147483647;
31+
files = (
32+
);
33+
runOnlyForDeploymentPostprocessing = 0;
34+
};
35+
/* End PBXFrameworksBuildPhase section */
36+
37+
/* Begin PBXGroup section */
38+
81DB95D41F49F72A005550D2 = {
39+
isa = PBXGroup;
40+
children = (
41+
81DB95DF1F49F72A005550D2 /* PresentationLayerTest */,
42+
81DB95DE1F49F72A005550D2 /* Products */,
43+
);
44+
sourceTree = "<group>";
45+
};
46+
81DB95DE1F49F72A005550D2 /* Products */ = {
47+
isa = PBXGroup;
48+
children = (
49+
81DB95DD1F49F72A005550D2 /* PresentationLayerTest.app */,
50+
);
51+
name = Products;
52+
sourceTree = "<group>";
53+
};
54+
81DB95DF1F49F72A005550D2 /* PresentationLayerTest */ = {
55+
isa = PBXGroup;
56+
children = (
57+
81DB95E01F49F72A005550D2 /* AppDelegate.swift */,
58+
81DB95E21F49F72A005550D2 /* ViewController.swift */,
59+
81DB95E41F49F72A005550D2 /* Main.storyboard */,
60+
81DB95E71F49F72A005550D2 /* Assets.xcassets */,
61+
81DB95E91F49F72A005550D2 /* LaunchScreen.storyboard */,
62+
81DB95EC1F49F72A005550D2 /* Info.plist */,
63+
);
64+
path = PresentationLayerTest;
65+
sourceTree = "<group>";
66+
};
67+
/* End PBXGroup section */
68+
69+
/* Begin PBXNativeTarget section */
70+
81DB95DC1F49F72A005550D2 /* PresentationLayerTest */ = {
71+
isa = PBXNativeTarget;
72+
buildConfigurationList = 81DB95EF1F49F72A005550D2 /* Build configuration list for PBXNativeTarget "PresentationLayerTest" */;
73+
buildPhases = (
74+
81DB95D91F49F72A005550D2 /* Sources */,
75+
81DB95DA1F49F72A005550D2 /* Frameworks */,
76+
81DB95DB1F49F72A005550D2 /* Resources */,
77+
);
78+
buildRules = (
79+
);
80+
dependencies = (
81+
);
82+
name = PresentationLayerTest;
83+
productName = PresentationLayerTest;
84+
productReference = 81DB95DD1F49F72A005550D2 /* PresentationLayerTest.app */;
85+
productType = "com.apple.product-type.application";
86+
};
87+
/* End PBXNativeTarget section */
88+
89+
/* Begin PBXProject section */
90+
81DB95D51F49F72A005550D2 /* Project object */ = {
91+
isa = PBXProject;
92+
attributes = {
93+
LastSwiftUpdateCheck = 0900;
94+
LastUpgradeCheck = 0900;
95+
ORGANIZATIONNAME = "Matt Neuburg";
96+
TargetAttributes = {
97+
81DB95DC1F49F72A005550D2 = {
98+
CreatedOnToolsVersion = 9.0;
99+
};
100+
};
101+
};
102+
buildConfigurationList = 81DB95D81F49F72A005550D2 /* Build configuration list for PBXProject "PresentationLayerTest" */;
103+
compatibilityVersion = "Xcode 8.0";
104+
developmentRegion = en;
105+
hasScannedForEncodings = 0;
106+
knownRegions = (
107+
en,
108+
Base,
109+
);
110+
mainGroup = 81DB95D41F49F72A005550D2;
111+
productRefGroup = 81DB95DE1F49F72A005550D2 /* Products */;
112+
projectDirPath = "";
113+
projectRoot = "";
114+
targets = (
115+
81DB95DC1F49F72A005550D2 /* PresentationLayerTest */,
116+
);
117+
};
118+
/* End PBXProject section */
119+
120+
/* Begin PBXResourcesBuildPhase section */
121+
81DB95DB1F49F72A005550D2 /* Resources */ = {
122+
isa = PBXResourcesBuildPhase;
123+
buildActionMask = 2147483647;
124+
files = (
125+
81DB95EB1F49F72A005550D2 /* LaunchScreen.storyboard in Resources */,
126+
81DB95E81F49F72A005550D2 /* Assets.xcassets in Resources */,
127+
81DB95E61F49F72A005550D2 /* Main.storyboard in Resources */,
128+
);
129+
runOnlyForDeploymentPostprocessing = 0;
130+
};
131+
/* End PBXResourcesBuildPhase section */
132+
133+
/* Begin PBXSourcesBuildPhase section */
134+
81DB95D91F49F72A005550D2 /* Sources */ = {
135+
isa = PBXSourcesBuildPhase;
136+
buildActionMask = 2147483647;
137+
files = (
138+
81DB95E31F49F72A005550D2 /* ViewController.swift in Sources */,
139+
81DB95E11F49F72A005550D2 /* AppDelegate.swift in Sources */,
140+
);
141+
runOnlyForDeploymentPostprocessing = 0;
142+
};
143+
/* End PBXSourcesBuildPhase section */
144+
145+
/* Begin PBXVariantGroup section */
146+
81DB95E41F49F72A005550D2 /* Main.storyboard */ = {
147+
isa = PBXVariantGroup;
148+
children = (
149+
81DB95E51F49F72A005550D2 /* Base */,
150+
);
151+
name = Main.storyboard;
152+
sourceTree = "<group>";
153+
};
154+
81DB95E91F49F72A005550D2 /* LaunchScreen.storyboard */ = {
155+
isa = PBXVariantGroup;
156+
children = (
157+
81DB95EA1F49F72A005550D2 /* Base */,
158+
);
159+
name = LaunchScreen.storyboard;
160+
sourceTree = "<group>";
161+
};
162+
/* End PBXVariantGroup section */
163+
164+
/* Begin XCBuildConfiguration section */
165+
81DB95ED1F49F72A005550D2 /* Debug */ = {
166+
isa = XCBuildConfiguration;
167+
buildSettings = {
168+
ALWAYS_SEARCH_USER_PATHS = NO;
169+
CLANG_ANALYZER_NONNULL = YES;
170+
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
171+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
172+
CLANG_CXX_LIBRARY = "libc++";
173+
CLANG_ENABLE_MODULES = YES;
174+
CLANG_ENABLE_OBJC_ARC = YES;
175+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
176+
CLANG_WARN_BOOL_CONVERSION = YES;
177+
CLANG_WARN_COMMA = YES;
178+
CLANG_WARN_CONSTANT_CONVERSION = YES;
179+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
180+
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
181+
CLANG_WARN_EMPTY_BODY = YES;
182+
CLANG_WARN_ENUM_CONVERSION = YES;
183+
CLANG_WARN_INFINITE_RECURSION = YES;
184+
CLANG_WARN_INT_CONVERSION = YES;
185+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
186+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
187+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
188+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
189+
CLANG_WARN_STRICT_PROTOTYPES = YES;
190+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
191+
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
192+
CLANG_WARN_UNREACHABLE_CODE = YES;
193+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
194+
CODE_SIGN_IDENTITY = "iPhone Developer";
195+
COPY_PHASE_STRIP = NO;
196+
DEBUG_INFORMATION_FORMAT = dwarf;
197+
ENABLE_STRICT_OBJC_MSGSEND = YES;
198+
ENABLE_TESTABILITY = YES;
199+
GCC_C_LANGUAGE_STANDARD = gnu11;
200+
GCC_DYNAMIC_NO_PIC = NO;
201+
GCC_NO_COMMON_BLOCKS = YES;
202+
GCC_OPTIMIZATION_LEVEL = 0;
203+
GCC_PREPROCESSOR_DEFINITIONS = (
204+
"DEBUG=1",
205+
"$(inherited)",
206+
);
207+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
208+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
209+
GCC_WARN_UNDECLARED_SELECTOR = YES;
210+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
211+
GCC_WARN_UNUSED_FUNCTION = YES;
212+
GCC_WARN_UNUSED_VARIABLE = YES;
213+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
214+
MTL_ENABLE_DEBUG_INFO = YES;
215+
ONLY_ACTIVE_ARCH = YES;
216+
SDKROOT = iphoneos;
217+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
218+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
219+
};
220+
name = Debug;
221+
};
222+
81DB95EE1F49F72A005550D2 /* Release */ = {
223+
isa = XCBuildConfiguration;
224+
buildSettings = {
225+
ALWAYS_SEARCH_USER_PATHS = NO;
226+
CLANG_ANALYZER_NONNULL = YES;
227+
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
228+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
229+
CLANG_CXX_LIBRARY = "libc++";
230+
CLANG_ENABLE_MODULES = YES;
231+
CLANG_ENABLE_OBJC_ARC = YES;
232+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
233+
CLANG_WARN_BOOL_CONVERSION = YES;
234+
CLANG_WARN_COMMA = YES;
235+
CLANG_WARN_CONSTANT_CONVERSION = YES;
236+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
237+
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
238+
CLANG_WARN_EMPTY_BODY = YES;
239+
CLANG_WARN_ENUM_CONVERSION = YES;
240+
CLANG_WARN_INFINITE_RECURSION = YES;
241+
CLANG_WARN_INT_CONVERSION = YES;
242+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
243+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
244+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
245+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
246+
CLANG_WARN_STRICT_PROTOTYPES = YES;
247+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
248+
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
249+
CLANG_WARN_UNREACHABLE_CODE = YES;
250+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
251+
CODE_SIGN_IDENTITY = "iPhone Developer";
252+
COPY_PHASE_STRIP = NO;
253+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
254+
ENABLE_NS_ASSERTIONS = NO;
255+
ENABLE_STRICT_OBJC_MSGSEND = YES;
256+
GCC_C_LANGUAGE_STANDARD = gnu11;
257+
GCC_NO_COMMON_BLOCKS = YES;
258+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
259+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
260+
GCC_WARN_UNDECLARED_SELECTOR = YES;
261+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
262+
GCC_WARN_UNUSED_FUNCTION = YES;
263+
GCC_WARN_UNUSED_VARIABLE = YES;
264+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
265+
MTL_ENABLE_DEBUG_INFO = NO;
266+
SDKROOT = iphoneos;
267+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
268+
VALIDATE_PRODUCT = YES;
269+
};
270+
name = Release;
271+
};
272+
81DB95F01F49F72A005550D2 /* Debug */ = {
273+
isa = XCBuildConfiguration;
274+
buildSettings = {
275+
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
276+
DEVELOPMENT_TEAM = W3LHX5RGV2;
277+
INFOPLIST_FILE = PresentationLayerTest/Info.plist;
278+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
279+
PRODUCT_BUNDLE_IDENTIFIER = com.neuburg.matt.PresentationLayerTest;
280+
PRODUCT_NAME = "$(TARGET_NAME)";
281+
SWIFT_VERSION = 4.0;
282+
TARGETED_DEVICE_FAMILY = "1,2";
283+
};
284+
name = Debug;
285+
};
286+
81DB95F11F49F72A005550D2 /* Release */ = {
287+
isa = XCBuildConfiguration;
288+
buildSettings = {
289+
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
290+
DEVELOPMENT_TEAM = W3LHX5RGV2;
291+
INFOPLIST_FILE = PresentationLayerTest/Info.plist;
292+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
293+
PRODUCT_BUNDLE_IDENTIFIER = com.neuburg.matt.PresentationLayerTest;
294+
PRODUCT_NAME = "$(TARGET_NAME)";
295+
SWIFT_VERSION = 4.0;
296+
TARGETED_DEVICE_FAMILY = "1,2";
297+
};
298+
name = Release;
299+
};
300+
/* End XCBuildConfiguration section */
301+
302+
/* Begin XCConfigurationList section */
303+
81DB95D81F49F72A005550D2 /* Build configuration list for PBXProject "PresentationLayerTest" */ = {
304+
isa = XCConfigurationList;
305+
buildConfigurations = (
306+
81DB95ED1F49F72A005550D2 /* Debug */,
307+
81DB95EE1F49F72A005550D2 /* Release */,
308+
);
309+
defaultConfigurationIsVisible = 0;
310+
defaultConfigurationName = Release;
311+
};
312+
81DB95EF1F49F72A005550D2 /* Build configuration list for PBXNativeTarget "PresentationLayerTest" */ = {
313+
isa = XCConfigurationList;
314+
buildConfigurations = (
315+
81DB95F01F49F72A005550D2 /* Debug */,
316+
81DB95F11F49F72A005550D2 /* Release */,
317+
);
318+
defaultConfigurationIsVisible = 0;
319+
defaultConfigurationName = Release;
320+
};
321+
/* End XCConfigurationList section */
322+
};
323+
rootObject = 81DB95D51F49F72A005550D2 /* Project object */;
324+
}

0 commit comments

Comments
 (0)