Skip to content

Commit 906fb95

Browse files
committed
Chapter 8
Chapter 8
1 parent ace904d commit 906fb95

File tree

17 files changed

+1094
-0
lines changed

17 files changed

+1094
-0
lines changed

08-UITableViewAndUITableViewController/08-UITableViewAndUITableViewController.xcodeproj/project.pbxproj

+428
Large diffs are not rendered by default.

08-UITableViewAndUITableViewController/08-UITableViewAndUITableViewController.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,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "2.0">
5+
<Breakpoints>
6+
<BreakpointProxy
7+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8+
<BreakpointContent
9+
shouldBeEnabled = "No"
10+
ignoreCount = "0"
11+
continueAfterRunningActions = "No"
12+
filePath = "08-UITableViewAndUITableViewController/BNRItemsTableViewController.swift"
13+
timestampString = "442030834.468367"
14+
startingColumnNumber = "9223372036854775807"
15+
endingColumnNumber = "9223372036854775807"
16+
startingLineNumber = "56"
17+
endingLineNumber = "56"
18+
landmarkName = "tableView(_:numberOfRowsInSection:)"
19+
landmarkType = "5">
20+
</BreakpointContent>
21+
</BreakpointProxy>
22+
</Breakpoints>
23+
</Bucket>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0610"
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 = "2D5F14EE1A58D946009C5D33"
18+
BuildableName = "08-UITableViewAndUITableViewController.app"
19+
BlueprintName = "08-UITableViewAndUITableViewController"
20+
ReferencedContainer = "container:08-UITableViewAndUITableViewController.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "YES"
26+
buildForProfiling = "NO"
27+
buildForArchiving = "NO"
28+
buildForAnalyzing = "YES">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "2D5F15031A58D946009C5D33"
32+
BuildableName = "08-UITableViewAndUITableViewControllerTests.xctest"
33+
BlueprintName = "08-UITableViewAndUITableViewControllerTests"
34+
ReferencedContainer = "container:08-UITableViewAndUITableViewController.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
37+
</BuildActionEntries>
38+
</BuildAction>
39+
<TestAction
40+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
41+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
42+
shouldUseLaunchSchemeArgsEnv = "YES"
43+
buildConfiguration = "Debug">
44+
<Testables>
45+
<TestableReference
46+
skipped = "NO">
47+
<BuildableReference
48+
BuildableIdentifier = "primary"
49+
BlueprintIdentifier = "2D5F15031A58D946009C5D33"
50+
BuildableName = "08-UITableViewAndUITableViewControllerTests.xctest"
51+
BlueprintName = "08-UITableViewAndUITableViewControllerTests"
52+
ReferencedContainer = "container:08-UITableViewAndUITableViewController.xcodeproj">
53+
</BuildableReference>
54+
</TestableReference>
55+
</Testables>
56+
<MacroExpansion>
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "2D5F14EE1A58D946009C5D33"
60+
BuildableName = "08-UITableViewAndUITableViewController.app"
61+
BlueprintName = "08-UITableViewAndUITableViewController"
62+
ReferencedContainer = "container:08-UITableViewAndUITableViewController.xcodeproj">
63+
</BuildableReference>
64+
</MacroExpansion>
65+
</TestAction>
66+
<LaunchAction
67+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
68+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
69+
launchStyle = "0"
70+
useCustomWorkingDirectory = "NO"
71+
buildConfiguration = "Debug"
72+
ignoresPersistentStateOnLaunch = "NO"
73+
debugDocumentVersioning = "YES"
74+
allowLocationSimulation = "YES">
75+
<BuildableProductRunnable>
76+
<BuildableReference
77+
BuildableIdentifier = "primary"
78+
BlueprintIdentifier = "2D5F14EE1A58D946009C5D33"
79+
BuildableName = "08-UITableViewAndUITableViewController.app"
80+
BlueprintName = "08-UITableViewAndUITableViewController"
81+
ReferencedContainer = "container:08-UITableViewAndUITableViewController.xcodeproj">
82+
</BuildableReference>
83+
</BuildableProductRunnable>
84+
<AdditionalOptions>
85+
</AdditionalOptions>
86+
</LaunchAction>
87+
<ProfileAction
88+
shouldUseLaunchSchemeArgsEnv = "YES"
89+
savedToolIdentifier = ""
90+
useCustomWorkingDirectory = "NO"
91+
buildConfiguration = "Release"
92+
debugDocumentVersioning = "YES">
93+
<BuildableProductRunnable>
94+
<BuildableReference
95+
BuildableIdentifier = "primary"
96+
BlueprintIdentifier = "2D5F14EE1A58D946009C5D33"
97+
BuildableName = "08-UITableViewAndUITableViewController.app"
98+
BlueprintName = "08-UITableViewAndUITableViewController"
99+
ReferencedContainer = "container:08-UITableViewAndUITableViewController.xcodeproj">
100+
</BuildableReference>
101+
</BuildableProductRunnable>
102+
</ProfileAction>
103+
<AnalyzeAction
104+
buildConfiguration = "Debug">
105+
</AnalyzeAction>
106+
<ArchiveAction
107+
buildConfiguration = "Release"
108+
revealArchiveInOrganizer = "YES">
109+
</ArchiveAction>
110+
</Scheme>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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>SchemeUserState</key>
6+
<dict>
7+
<key>08-UITableViewAndUITableViewController.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>2D5F14EE1A58D946009C5D33</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
<key>2D5F15031A58D946009C5D33</key>
21+
<dict>
22+
<key>primary</key>
23+
<true/>
24+
</dict>
25+
</dict>
26+
</dict>
27+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// AppDelegate.swift
3+
// 08-UITableViewAndUITableViewController
4+
//
5+
// Created by Raza Master on 1/3/15.
6+
// Copyright (c) 2015 raza. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
@UIApplicationMain
12+
class AppDelegate: UIResponder, UIApplicationDelegate {
13+
14+
var window: UIWindow?
15+
16+
17+
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
18+
// Override point for customization after application launch.
19+
20+
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
21+
22+
//Override point for customization after applicaiton launch
23+
24+
//Create a BNRItemViewContoller
25+
let itemsViewController = BNRItemsTableViewController()
26+
27+
//Place BNRItemsViewController's Table view in the window hierarchy
28+
self.window!.rootViewController = itemsViewController
29+
30+
self.window!.backgroundColor = UIColor.whiteColor()
31+
self.window!.makeKeyAndVisible()
32+
33+
return true
34+
}
35+
36+
func applicationWillResignActive(application: UIApplication!) {
37+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
38+
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
39+
}
40+
41+
func applicationDidEnterBackground(application: UIApplication!) {
42+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
43+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
44+
}
45+
46+
func applicationWillEnterForeground(application: UIApplication!) {
47+
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
48+
}
49+
50+
func applicationDidBecomeActive(application: UIApplication!) {
51+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
52+
}
53+
54+
func applicationWillTerminate(application: UIApplication!) {
55+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
56+
}
57+
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// BNRItem.swift
3+
// 08-UITableViewAndUITableViewController
4+
//
5+
// Created by Raza Master on 1/3/15.
6+
// Copyright (c) 2015 raza. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class BNRItem: NSObject {
12+
13+
var itemName: String
14+
var serialNumber: String
15+
var valueInDollars: Int
16+
var dateCreated: NSDate
17+
18+
override var description: String {
19+
return "\(itemName) (\(serialNumber)): Worth $\(valueInDollars), recorded on \(dateCreated)"
20+
}
21+
22+
init(itemName name: String, valueInDollars value: Int, serialNumber sNumber: String) {
23+
// Give the instance variables initial values
24+
itemName = name
25+
serialNumber = sNumber
26+
valueInDollars = value
27+
dateCreated = NSDate()
28+
29+
super.init()
30+
}
31+
32+
convenience init(itemName name: String) {
33+
self.init(itemName: name, valueInDollars: 0, serialNumber: "")
34+
}
35+
36+
convenience override init() {
37+
self.init(itemName: "", valueInDollars: 0, serialNumber: "")
38+
}
39+
40+
// A class method for the type Item itself, not Item instances
41+
class func randomItem() -> BNRItem {
42+
let randomAdjectiveList = ["Fluffy", "Rusty", "Shiny"]
43+
let randomNounList = ["Bear", "Spork", "Mac"]
44+
45+
// Get the index of a random adjective/noun from the lists
46+
let adjectiveIndex = Int(arc4random() % UInt32(randomAdjectiveList.count))
47+
let nounIndex = Int(arc4random() % UInt32(randomNounList.count))
48+
49+
let randomName = "\(randomAdjectiveList[adjectiveIndex]) \(randomNounList[nounIndex])"
50+
51+
let randomValue = Int(arc4random() % 100)
52+
let randomSerialNumber = "0\(arc4random() % 10)A\(arc4random() % 26)0\(arc4random() % 10)"
53+
54+
return BNRItem(itemName: randomName, valueInDollars: randomValue, serialNumber: randomSerialNumber)
55+
}
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// BNRItemStore.swift
3+
// 08-UITableViewAndUITableViewController
4+
//
5+
// Created by Raza Master on 1/3/15.
6+
// Copyright (c) 2015 raza. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
let GlobalStoreShare = BNRItemStore()
12+
class BNRItemStore: NSObject {
13+
14+
//Notice that this is a class method
15+
class var sharedStore:BNRItemStore{
16+
return GlobalStoreShare
17+
}
18+
19+
var _privateItems = [BNRItem]()
20+
21+
var allItems:[BNRItem]{
22+
return _privateItems
23+
}
24+
25+
func allItemsMoreThanFif() -> [BNRItem]{
26+
return _privateItems.filter({$0.valueInDollars > 50})
27+
}
28+
29+
func allItemsLessThanFif() -> [BNRItem]{
30+
return _privateItems.filter({$0.valueInDollars <= 50})
31+
}
32+
33+
func createItem() -> BNRItem{
34+
let item = BNRItem.randomItem()
35+
_privateItems.append(item)
36+
return item
37+
}
38+
39+
}

0 commit comments

Comments
 (0)