Skip to content

Commit fc90ad9

Browse files
committed
Xcode 6.1.1
Chapter 11 Xcode 6.1.1
1 parent 1f39b73 commit fc90ad9

22 files changed

+1679
-0
lines changed

11-Camera/Camera.xcodeproj/project.pbxproj

+443
Large diffs are not rendered by default.

11-Camera/Camera.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,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 = "2DE8CFC01A64847B005C8B35"
18+
BuildableName = "Camera.app"
19+
BlueprintName = "Camera"
20+
ReferencedContainer = "container:Camera.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 = "2DE8CFD51A64847C005C8B35"
32+
BuildableName = "CameraTests.xctest"
33+
BlueprintName = "CameraTests"
34+
ReferencedContainer = "container:Camera.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 = "2DE8CFD51A64847C005C8B35"
50+
BuildableName = "CameraTests.xctest"
51+
BlueprintName = "CameraTests"
52+
ReferencedContainer = "container:Camera.xcodeproj">
53+
</BuildableReference>
54+
</TestableReference>
55+
</Testables>
56+
<MacroExpansion>
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "2DE8CFC01A64847B005C8B35"
60+
BuildableName = "Camera.app"
61+
BlueprintName = "Camera"
62+
ReferencedContainer = "container:Camera.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 = "2DE8CFC01A64847B005C8B35"
79+
BuildableName = "Camera.app"
80+
BlueprintName = "Camera"
81+
ReferencedContainer = "container:Camera.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 = "2DE8CFC01A64847B005C8B35"
97+
BuildableName = "Camera.app"
98+
BlueprintName = "Camera"
99+
ReferencedContainer = "container:Camera.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>Camera.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>2DE8CFC01A64847B005C8B35</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
<key>2DE8CFD51A64847C005C8B35</key>
21+
<dict>
22+
<key>primary</key>
23+
<true/>
24+
</dict>
25+
</dict>
26+
</dict>
27+
</plist>

11-Camera/Camera/AppDelegate.swift

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// AppDelegate.swift
3+
// chap11
4+
//
5+
// Created by PanaCloud on 7/22/14.
6+
// Copyright (c) 2014 PanaCloud. 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+
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
19+
20+
//Override point for customization after applicaiton launch
21+
22+
//Create a BNRItemViewContoller
23+
let itemsViewController = BNRItemsTableViewController()
24+
25+
26+
//Create an instance of a UINavigationController
27+
//its stack contains only itemsViewController
28+
let navcontroller = UINavigationController(rootViewController: itemsViewController)
29+
30+
31+
//Place BNRItemsViewController's Table view in the window hierarchy
32+
self.window!.rootViewController = navcontroller
33+
34+
self.window!.backgroundColor = UIColor.whiteColor()
35+
self.window!.makeKeyAndVisible()
36+
37+
return true
38+
39+
}
40+
41+
func applicationWillResignActive(application: UIApplication!) {
42+
// 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.
43+
// 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.
44+
}
45+
46+
func applicationDidEnterBackground(application: UIApplication!) {
47+
// 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.
48+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
49+
}
50+
51+
func applicationWillEnterForeground(application: UIApplication!) {
52+
// 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.
53+
}
54+
55+
func applicationDidBecomeActive(application: UIApplication!) {
56+
// 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.
57+
}
58+
59+
func applicationWillTerminate(application: UIApplication!) {
60+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
61+
}
62+
63+
64+
}
65+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//
2+
// BNRDetailViewController.swift
3+
// chap10
4+
//
5+
// Created by PanaCloud on 7/19/14.
6+
// Copyright (c) 2014 PanaCloud. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class BNRDetailViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate{
12+
13+
required init(coder aDecoder: NSCoder) {
14+
super.init(coder: aDecoder)
15+
}
16+
17+
override init() {
18+
super.init()
19+
}
20+
21+
override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
22+
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
23+
}
24+
25+
@IBOutlet var dateLabel: UILabel!
26+
@IBOutlet var valueField: UITextField!
27+
@IBOutlet var serialNumberfield: UITextField!
28+
@IBOutlet var nameField: UITextField!
29+
30+
@IBOutlet var imageView: UIImageView!
31+
32+
var imagePicker = UIImagePickerController()
33+
34+
@IBAction func takePicture(sender: AnyObject) {
35+
36+
//If the device has a camera, take a picture, otherwise,
37+
//just pick from photo library
38+
39+
if(UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
40+
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
41+
}else{
42+
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
43+
}
44+
imagePicker.delegate = self
45+
46+
//Place image picker on the Screen
47+
self.presentViewController(imagePicker, animated: true, completion: nil)
48+
}
49+
50+
override func viewDidLoad() {
51+
super.viewDidLoad()
52+
53+
54+
55+
// Do any additional setup after loading the view.
56+
}
57+
58+
override func didReceiveMemoryWarning() {
59+
super.didReceiveMemoryWarning()
60+
// Dispose of any resources that can be recreated.
61+
}
62+
63+
var item = BNRItem()
64+
65+
override func viewWillAppear(animated: Bool) {
66+
super.viewWillAppear(true)
67+
68+
self.nameField.text = item.itemName
69+
self.serialNumberfield.text = item.serialNumber
70+
self.valueField.text = "\(item.valueInDollars)"
71+
self.navigationItem.title = item.itemName
72+
73+
//We need an NSDateFormatter that will turn a date into a simple date string
74+
var dateFormatter:NSDateFormatter!
75+
if(dateFormatter == nil){
76+
dateFormatter = NSDateFormatter()
77+
dateFormatter.dateStyle = NSDateFormatterStyle.MediumStyle
78+
dateFormatter.timeStyle = NSDateFormatterStyle.NoStyle
79+
}
80+
81+
//use filtered NSdate object to set dateLabel contents
82+
self.dateLabel.text = dateFormatter.stringFromDate(item.dateCreated)
83+
84+
var imageKey = self.item.itemKey
85+
86+
//Get the image for ites image key from the image store
87+
var imageToDisplay:UIImage = BNRImageStore.sharedStore.imageForKey(imageKey)
88+
89+
//Use that image to put on the screen in the image view
90+
self.imageView.image = imageToDisplay
91+
92+
}
93+
94+
95+
override func viewWillDisappear(animated: Bool) {
96+
super.viewWillDisappear(true)
97+
98+
//Clear first responder
99+
self.view.endEditing(true)
100+
101+
//"Save" changes to item
102+
var item = self.item
103+
item.itemName = self.nameField.text
104+
item.serialNumber = self.serialNumberfield.text
105+
item.valueInDollars = self.valueField.text.toInt()!
106+
107+
}
108+
109+
110+
func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]!) {
111+
112+
//Get picked image from info dictionary
113+
var image = info[UIImagePickerControllerOriginalImage] as UIImage
114+
115+
// Store the image in the BNRImageStore for this key
116+
BNRImageStore.sharedStore.setImage(image, forKey: self.item.itemKey)
117+
118+
//Put that image onto the screen in our image view
119+
self.imageView.image = image
120+
121+
imagePicker.allowsEditing = true
122+
123+
//Take image picker off the screen
124+
// you must call this dismiss method
125+
self.dismissViewControllerAnimated(true, completion: nil)
126+
}
127+
128+
func textFieldShouldReturn(textField: UITextField!) -> Bool {
129+
textField.resignFirstResponder()
130+
return true
131+
}
132+
133+
@IBAction func backgroundTapped(sender: AnyObject) {
134+
self.view.endEditing(true)
135+
}
136+
}

0 commit comments

Comments
 (0)