Skip to content

Commit cbb17f1

Browse files
committed
mild cleanup; new examples
1 parent 2169b8d commit cbb17f1

File tree

82 files changed

+1527
-25
lines changed

Some content is hidden

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

82 files changed

+1527
-25
lines changed

bk2ch08p398cellBackgroundLayeringNewStyle/CellConfiguration.xcodeproj/project.pbxproj

-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
/* Begin PBXBuildFile section */
1010
81BF7A7C24C9CF5F0090DA76 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81BF7A7B24C9CF5F0090DA76 /* AppDelegate.swift */; };
1111
81BF7A7E24C9CF5F0090DA76 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81BF7A7D24C9CF5F0090DA76 /* SceneDelegate.swift */; };
12-
81BF7A8324C9CF5F0090DA76 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81BF7A8124C9CF5F0090DA76 /* Main.storyboard */; };
1312
81BF7A8524C9CF600090DA76 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 81BF7A8424C9CF600090DA76 /* Assets.xcassets */; };
1413
81BF7A8824C9CF600090DA76 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81BF7A8624C9CF600090DA76 /* LaunchScreen.storyboard */; };
1514
81BF7A9024C9CFCB0090DA76 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 81BF7A8F24C9CFCB0090DA76 /* RootViewController.xib */; };
@@ -21,7 +20,6 @@
2120
81BF7A7824C9CF5F0090DA76 /* CellConfiguration.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CellConfiguration.app; sourceTree = BUILT_PRODUCTS_DIR; };
2221
81BF7A7B24C9CF5F0090DA76 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2322
81BF7A7D24C9CF5F0090DA76 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
24-
81BF7A8224C9CF5F0090DA76 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
2523
81BF7A8424C9CF600090DA76 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2624
81BF7A8724C9CF600090DA76 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2725
81BF7A8924C9CF600090DA76 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -65,7 +63,6 @@
6563
81BF7A9124C9CFD70090DA76 /* RootViewController.swift */,
6664
81BF7A8F24C9CFCB0090DA76 /* RootViewController.xib */,
6765
81BF7A9324C9D5840090DA76 /* linen.png */,
68-
81BF7A8124C9CF5F0090DA76 /* Main.storyboard */,
6966
81BF7A8424C9CF600090DA76 /* Assets.xcassets */,
7067
81BF7A8624C9CF600090DA76 /* LaunchScreen.storyboard */,
7168
81BF7A8924C9CF600090DA76 /* Info.plist */,
@@ -134,7 +131,6 @@
134131
81BF7A8524C9CF600090DA76 /* Assets.xcassets in Resources */,
135132
81BF7A9424C9D5840090DA76 /* linen.png in Resources */,
136133
81BF7A9024C9CFCB0090DA76 /* RootViewController.xib in Resources */,
137-
81BF7A8324C9CF5F0090DA76 /* Main.storyboard in Resources */,
138134
);
139135
runOnlyForDeploymentPostprocessing = 0;
140136
};
@@ -154,14 +150,6 @@
154150
/* End PBXSourcesBuildPhase section */
155151

156152
/* Begin PBXVariantGroup section */
157-
81BF7A8124C9CF5F0090DA76 /* Main.storyboard */ = {
158-
isa = PBXVariantGroup;
159-
children = (
160-
81BF7A8224C9CF5F0090DA76 /* Base */,
161-
);
162-
name = Main.storyboard;
163-
sourceTree = "<group>";
164-
};
165153
81BF7A8624C9CF600090DA76 /* LaunchScreen.storyboard */ = {
166154
isa = PBXVariantGroup;
167155
children = (

bk2ch08p398cellBackgroundLayeringNewStyle/CellConfiguration/Info.plist

-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
<string>Default Configuration</string>
3434
<key>UISceneDelegateClassName</key>
3535
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
36-
<key>UISceneStoryboardFile</key>
37-
<string>Main</string>
3836
</dict>
3937
</array>
4038
</dict>
@@ -43,8 +41,6 @@
4341
<true/>
4442
<key>UILaunchStoryboardName</key>
4543
<string>LaunchScreen</string>
46-
<key>UIMainStoryboardFile</key>
47-
<string>Main</string>
4844
<key>UIRequiredDeviceCapabilities</key>
4945
<array>
5046
<string>armv7</string>

bk2ch08p398cellBackgroundLayeringNewStyle/CellConfiguration/RootViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RootViewController : UITableViewController {
4949

5050
class MyCell : UITableViewCell {
5151
override func updateConfiguration(using state: UICellConfigurationState) {
52-
var back = UIBackgroundConfiguration.listPlainCell()
52+
var back = UIBackgroundConfiguration.listPlainCell().updated(for: state)
5353
let v = UIImageView(image: UIImage(named:"linen.png"))
5454
v.contentMode = .scaleToFill
5555
// there is no selectedCustomView; we just change the custom view _ourselves_ when selected

bk2ch08p416sectionsDiffableDataSource2/ch21p718sections.xcodeproj/project.pbxproj

+533
Large diffs are not rendered by default.

bk2ch08p416sectionsDiffableDataSource2/ch21p718sections.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
import UIKit
3+
4+
@UIApplicationMain
5+
class AppDelegate : UIResponder, UIApplicationDelegate {
6+
var window : UIWindow?
7+
8+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool {
9+
10+
self.window = self.window ?? UIWindow()
11+
self.window!.rootViewController = RootViewController(nibName: "RootViewController", bundle: nil)
12+
self.window!.backgroundColor = .white
13+
self.window!.makeKeyAndVisible()
14+
return true
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "29x29",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "29x29",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "40x40",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "40x40",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "60x60",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "60x60",
31+
"scale" : "3x"
32+
}
33+
],
34+
"info" : {
35+
"version" : 1,
36+
"author" : "xcode"
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"orientation" : "portrait",
5+
"idiom" : "iphone",
6+
"extent" : "full-screen",
7+
"minimum-system-version" : "7.0",
8+
"scale" : "2x"
9+
},
10+
{
11+
"orientation" : "portrait",
12+
"idiom" : "iphone",
13+
"subtype" : "retina4",
14+
"extent" : "full-screen",
15+
"minimum-system-version" : "7.0",
16+
"scale" : "2x"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8152.3" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8124.4"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="EHf-IW-A2E">
10+
<objects>
11+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
14+
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
17+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
20+
</view>
21+
</viewController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
23+
</objects>
24+
<point key="canvasLocation" x="53" y="375"/>
25+
</scene>
26+
</scenes>
27+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
import UIKit
3+
4+
// move everything into the data source object!
5+
6+
class MyDataSource: UITableViewDiffableDataSource<String, String> {
7+
let cellID = "Cell"
8+
let headerID = "Header"
9+
init(tableView: UITableView) {
10+
// table view configuration
11+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: self.cellID)
12+
tableView.register(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: self.headerID)
13+
tableView.sectionIndexColor = .white
14+
tableView.sectionIndexBackgroundColor = .red
15+
tableView.sectionIndexTrackingBackgroundColor = .blue
16+
let cellID = self.cellID
17+
super.init(tableView: tableView) { tv,ip,s in
18+
let cell = tv.dequeueReusableCell(withIdentifier: cellID, for: ip)
19+
cell.textLabel!.text = s
20+
21+
var stateName = s
22+
stateName = stateName.lowercased()
23+
stateName = stateName.replacingOccurrences(of: " ", with:"")
24+
stateName = "flag_\(stateName).gif"
25+
let im = UIImage(named: stateName)
26+
cell.imageView!.image = im
27+
28+
return cell
29+
}
30+
self.populate()
31+
}
32+
private func populate() {
33+
let s = try! String(
34+
contentsOfFile: Bundle.main.path(
35+
forResource: "states", ofType: "txt")!)
36+
let states = s.components(separatedBy:"\n")
37+
let d = Dictionary(grouping: states) {String($0.prefix(1))}
38+
let sections = Array(d).sorted{$0.key < $1.key} // *
39+
40+
var snap = NSDiffableDataSourceSnapshot<String,String>()
41+
for section in sections {
42+
snap.appendSections([section.0])
43+
snap.appendItems(section.1)
44+
}
45+
self.apply(snap, animatingDifferences: false)
46+
}
47+
override func sectionIndexTitles(for tableView: UITableView) -> [String]? {
48+
return self.snapshot().sectionIdentifiers
49+
}
50+
override func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
51+
return self.snapshot().sectionIdentifiers.firstIndex(of: title) ?? 0
52+
}
53+
}
54+
extension MyDataSource : UITableViewDelegate {
55+
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
56+
let h = tableView.dequeueReusableHeaderFooterView(withIdentifier: self.headerID)!
57+
h.tintColor = .red
58+
if h.viewWithTag(1) == nil {
59+
print("configuring a new header view") // only called about 8 times
60+
61+
h.backgroundView = UIView()
62+
h.backgroundView?.backgroundColor = .black
63+
let lab = UILabel()
64+
lab.tag = 1
65+
lab.font = UIFont(name:"Georgia-Bold", size:22)
66+
lab.textColor = .green
67+
lab.backgroundColor = .clear
68+
h.contentView.addSubview(lab)
69+
let v = UIImageView()
70+
v.tag = 2
71+
v.backgroundColor = .black
72+
v.image = UIImage(named:"us_flag_small.gif")
73+
h.contentView.addSubview(v)
74+
lab.translatesAutoresizingMaskIntoConstraints = false
75+
v.translatesAutoresizingMaskIntoConstraints = false
76+
NSLayoutConstraint.activate([
77+
NSLayoutConstraint.constraints(withVisualFormat:"H:|-5-[lab(25)]-10-[v(40)]",
78+
metrics:nil, views:["v":v, "lab":lab]),
79+
NSLayoutConstraint.constraints(withVisualFormat:"V:|[v]|",
80+
metrics:nil, views:["v":v]),
81+
NSLayoutConstraint.constraints(withVisualFormat:"V:|[lab]|",
82+
metrics:nil, views:["lab":lab])
83+
].flatMap{$0})
84+
}
85+
let lab = h.contentView.viewWithTag(1) as! UILabel
86+
lab.text = self.snapshot().sectionIdentifiers[section] // *
87+
return h
88+
89+
}
90+
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
3+
import UIKit
4+
5+
class RootViewController : UITableViewController {
6+
7+
lazy var datasource = MyDataSource(tableView: self.tableView)
8+
9+
override var prefersStatusBarHidden : Bool {
10+
return true
11+
}
12+
13+
override func viewDidLoad() {
14+
super.viewDidLoad()
15+
self.tableView.delegate = self.datasource
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14092" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14081.1"/>
9+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
11+
</dependencies>
12+
<objects>
13+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RootViewController" customModule="ch21p718sections" customModuleProvider="target">
14+
<connections>
15+
<outlet property="view" destination="4" id="5"/>
16+
</connections>
17+
</placeholder>
18+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
19+
<tableView opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" bouncesZoom="NO" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="4">
20+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
21+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
22+
<color key="backgroundColor" red="0.50076308140000003" green="1" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
23+
<viewLayoutGuide key="safeArea" id="lKe-QA-EXW"/>
24+
<connections>
25+
<outlet property="dataSource" destination="-1" id="6"/>
26+
<outlet property="delegate" destination="-1" id="7"/>
27+
</connections>
28+
<point key="canvasLocation" x="26" y="52"/>
29+
</tableView>
30+
</objects>
31+
</document>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>${PRODUCT_NAME}</string>
9+
<key>CFBundleExecutable</key>
10+
<string>${EXECUTABLE_NAME}</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>${PRODUCT_NAME}</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleSignature</key>
22+
<string>????</string>
23+
<key>CFBundleVersion</key>
24+
<string>1.0</string>
25+
<key>LSRequiresIPhoneOS</key>
26+
<true/>
27+
<key>UILaunchStoryboardName</key>
28+
<string>LaunchScreen</string>
29+
<key>UIRequiredDeviceCapabilities</key>
30+
<array>
31+
<string>armv7</string>
32+
</array>
33+
<key>UISupportedInterfaceOrientations</key>
34+
<array>
35+
<string>UIInterfaceOrientationPortrait</string>
36+
<string>UIInterfaceOrientationLandscapeLeft</string>
37+
<string>UIInterfaceOrientationLandscapeRight</string>
38+
</array>
39+
</dict>
40+
</plist>

0 commit comments

Comments
 (0)