Skip to content

Commit c00aa02

Browse files
committed
starting chapter 5
1 parent 9d004c1 commit c00aa02

File tree

10 files changed

+362
-2
lines changed

10 files changed

+362
-2
lines changed

bk1ch04p204PlayingWithPackages/PlayingWithPackages/ViewController.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,16 @@ class ViewController: UIViewController {
269269

270270
do {
271271
// striding; basically an alternative to the stride global?
272-
stride(from: 1, to: 10, by: 2)
273-
(1...10).striding(by:2)
272+
for i in stride(from: 1, to: 10, by: 2) {
273+
print(i)
274+
}
275+
for i in (1...10).striding(by:2) /*.striding(by:3)*/ {
276+
print(i)
277+
}
278+
let planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter"]
279+
for planet in planets.striding(by:2) {
280+
print(planet) // Mercury, Earth, Jupiter
281+
}
274282
// a difference is that the latter results in a StrideCollection object that itself has a `stride` method that results in another, and so on
275283
}
276284

bk1ch04p204arrays/bk1ch04p204collections/ViewController.swift

+32
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,38 @@ class ViewController: UIViewController {
384384

385385
}
386386

387+
do {
388+
// it appears that these are two different methods
389+
// with two different complexities
390+
let arr = [1,2,3,4,5]
391+
let rev = arr.reversed() // Collection, O(1)
392+
for i in rev {
393+
print(i)
394+
}
395+
// I'm very confused and surprised by this
396+
let nextToLast = arr.reversed()[1] // Sequence, O(n)!
397+
print(nextToLast)
398+
399+
let nextToLast2 = arr.reversed()._base[1] // Collection again
400+
print(nextToLast2) // but wrong answer, it's still 4 because it's the base
401+
402+
var arr2 = arr
403+
arr2.reverse()
404+
print(arr2)
405+
406+
let slice = arr[1...2]
407+
print(slice.reversed().indices)
408+
409+
}
410+
411+
do { // well, this didn't work
412+
var arr = [1,2,3]
413+
let rev = arr.reversed()
414+
// let i = rev[1] // what??? compile error!!!!
415+
arr[1] = 20
416+
print(rev[rev.index(after:rev.startIndex)])
417+
}
418+
387419
do {
388420
struct Person {
389421
let firstName: String

bk1ch05p227branching/bk1ch05p227branching.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
buildSettings = {
275275
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
276276
INFOPLIST_FILE = bk1ch05p227branching/Info.plist;
277+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
277278
LD_RUNPATH_SEARCH_PATHS = (
278279
"$(inherited)",
279280
"@executable_path/Frameworks",
@@ -289,6 +290,7 @@
289290
buildSettings = {
290291
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
291292
INFOPLIST_FILE = bk1ch05p227branching/Info.plist;
293+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
292294
LD_RUNPATH_SEARCH_PATHS = (
293295
"$(inherited)",
294296
"@executable_path/Frameworks",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1300"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "32A5A8171AFA5B9A0035587B"
18+
BuildableName = "bk1ch05p227branching.app"
19+
BlueprintName = "bk1ch05p227branching"
20+
ReferencedContainer = "container:bk1ch05p227branching.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "32A5A8171AFA5B9A0035587B"
48+
BuildableName = "bk1ch05p227branching.app"
49+
BlueprintName = "bk1ch05p227branching"
50+
ReferencedContainer = "container:bk1ch05p227branching.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "32A5A8171AFA5B9A0035587B"
65+
BuildableName = "bk1ch05p227branching.app"
66+
BlueprintName = "bk1ch05p227branching"
67+
ReferencedContainer = "container:bk1ch05p227branching.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

bk1ch05p230switch/bk1ch05p230switch.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
284284
CLANG_ENABLE_MODULES = YES;
285285
INFOPLIST_FILE = bk1ch05p230switch/Info.plist;
286+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
286287
LD_RUNPATH_SEARCH_PATHS = (
287288
"$(inherited)",
288289
"@executable_path/Frameworks",
@@ -301,6 +302,7 @@
301302
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
302303
CLANG_ENABLE_MODULES = YES;
303304
INFOPLIST_FILE = bk1ch05p230switch/Info.plist;
305+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
304306
LD_RUNPATH_SEARCH_PATHS = (
305307
"$(inherited)",
306308
"@executable_path/Frameworks",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1300"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "32A5A8451AFA6FA30035587B"
18+
BuildableName = "bk1ch05p230switch.app"
19+
BlueprintName = "bk1ch05p230switch"
20+
ReferencedContainer = "container:bk1ch05p230switch.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "32A5A8451AFA6FA30035587B"
48+
BuildableName = "bk1ch05p230switch.app"
49+
BlueprintName = "bk1ch05p230switch"
50+
ReferencedContainer = "container:bk1ch05p230switch.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "32A5A8451AFA6FA30035587B"
65+
BuildableName = "bk1ch05p230switch.app"
66+
BlueprintName = "bk1ch05p230switch"
67+
ReferencedContainer = "container:bk1ch05p230switch.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

bk1ch05p237conditionalEvaluation/bk1ch05p237conditionalEvaluation.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
buildSettings = {
275275
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
276276
INFOPLIST_FILE = bk1ch05p237conditionalEvaluation/Info.plist;
277+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
277278
LD_RUNPATH_SEARCH_PATHS = (
278279
"$(inherited)",
279280
"@executable_path/Frameworks",
@@ -289,6 +290,7 @@
289290
buildSettings = {
290291
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
291292
INFOPLIST_FILE = bk1ch05p237conditionalEvaluation/Info.plist;
293+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
292294
LD_RUNPATH_SEARCH_PATHS = (
293295
"$(inherited)",
294296
"@executable_path/Frameworks",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1300"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "32A5A8731AFA7D3B0035587B"
18+
BuildableName = "bk1ch05p237conditionalEvaluation.app"
19+
BlueprintName = "bk1ch05p237conditionalEvaluation"
20+
ReferencedContainer = "container:bk1ch05p237conditionalEvaluation.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "32A5A8731AFA7D3B0035587B"
48+
BuildableName = "bk1ch05p237conditionalEvaluation.app"
49+
BlueprintName = "bk1ch05p237conditionalEvaluation"
50+
ReferencedContainer = "container:bk1ch05p237conditionalEvaluation.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "32A5A8731AFA7D3B0035587B"
65+
BuildableName = "bk1ch05p237conditionalEvaluation.app"
66+
BlueprintName = "bk1ch05p237conditionalEvaluation"
67+
ReferencedContainer = "container:bk1ch05p237conditionalEvaluation.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

bk1ch05p239loops/bk1ch05p239loops.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
284284
CLANG_ENABLE_MODULES = YES;
285285
INFOPLIST_FILE = bk1ch05p239loops/Info.plist;
286+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
286287
LD_RUNPATH_SEARCH_PATHS = (
287288
"$(inherited)",
288289
"@executable_path/Frameworks",
@@ -301,6 +302,7 @@
301302
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
302303
CLANG_ENABLE_MODULES = YES;
303304
INFOPLIST_FILE = bk1ch05p239loops/Info.plist;
305+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
304306
LD_RUNPATH_SEARCH_PATHS = (
305307
"$(inherited)",
306308
"@executable_path/Frameworks",

0 commit comments

Comments
 (0)