Skip to content

Commit 3258ddc

Browse files
committed
Updated all code for Xcode Version 6.3 Beta 1 (6D520o)
1 parent eed098f commit 3258ddc

File tree

93 files changed

+398
-414
lines changed

Some content is hidden

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

93 files changed

+398
-414
lines changed

chapter-addressBook/Retrieving Properties of Address Book Entries/Retrieving Properties of Address Book Entries/AppDelegate.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@
7777
// for person: ABRecordRef in allPeople{
7878
//
7979
// let firstName = ABRecordCopyValue(person,
80-
// kABPersonFirstNameProperty).takeRetainedValue() as String
80+
// kABPersonFirstNameProperty).takeRetainedValue() as! String
8181
//
8282
// let lastName = ABRecordCopyValue(person,
83-
// kABPersonLastNameProperty).takeRetainedValue() as String
83+
// kABPersonLastNameProperty).takeRetainedValue() as! String
8484
//
8585
// let email: ABMultiValueRef = ABRecordCopyValue(person,
8686
// kABPersonEmailProperty).takeRetainedValue()
@@ -151,7 +151,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
151151
for counter in 0..<ABMultiValueGetCount(emails){
152152

153153
let email = ABMultiValueCopyValueAtIndex(emails,
154-
counter).takeRetainedValue() as String
154+
counter).takeRetainedValue() as! String
155155

156156
println(email)
157157

@@ -168,9 +168,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
168168
for person: ABRecordRef in allPeople{
169169

170170
let firstName = ABRecordCopyValue(person,
171-
kABPersonFirstNameProperty).takeRetainedValue() as String
171+
kABPersonFirstNameProperty).takeRetainedValue() as! String
172172
let lastName = ABRecordCopyValue(person,
173-
kABPersonLastNameProperty).takeRetainedValue() as String
173+
kABPersonLastNameProperty).takeRetainedValue() as! String
174174

175175
println("First name = \(firstName)")
176176
println("Last name = \(lastName)")

chapter-addressBook/Retrieving a Person Entity with System UI/Retrieving a Person Entity with System UI/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
//
6464
// for index in 0..<countOfPhones{
6565
// let phone = ABMultiValueCopyValueAtIndex(phones,
66-
// index).takeRetainedValue() as String
66+
// index).takeRetainedValue() as! String
6767
//
6868
// println(phone)
6969
//

chapter-addressBook/Retrieving a Property of a Person Entity with System UI/Retrieving a Property of a Person Entity with System UI/ViewController.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ ABPeoplePickerNavigationControllerDelegate {
5959
let index = Int(identifier) as CFIndex
6060

6161
let address: NSDictionary = ABMultiValueCopyValueAtIndex(addresses,
62-
index).takeRetainedValue() as NSDictionary
62+
index).takeRetainedValue() as! NSDictionary
6363

64-
let country = address[kABPersonAddressCountryKey as String] as String
65-
let city = address[kABPersonAddressCityKey as String] as String
66-
let street = address[kABPersonAddressStreetKey as String] as String
64+
let country = address[kABPersonAddressCountryKey as String] as! String
65+
let city = address[kABPersonAddressCityKey as String] as! String
66+
let street = address[kABPersonAddressStreetKey as String] as! String
6767

6868
println("Country = \(country)")
6969
println("City = \(city)")

chapter-addressBook/Retrieving and Setting a Person's Address Book Image/Retrieving and Setting a Person's Address Book Image/AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3737

3838
func imageForPerson(person: ABRecordRef) -> UIImage?{
3939

40-
let data = ABPersonCopyImageData(person).takeRetainedValue() as NSData
40+
let data = ABPersonCopyImageData(person).takeRetainedValue() as! NSData
4141

4242
let image = UIImage(data: data)
4343
return image

chapter-addressBook/Searching the Address Book/Searching the Address Book/AppDelegate.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4646
for person: ABRecordRef in people{
4747

4848
let firstName = ABRecordCopyValue(person,
49-
kABPersonFirstNameProperty).takeRetainedValue() as String
49+
kABPersonFirstNameProperty).takeRetainedValue() as! String
5050

5151
let lastName = ABRecordCopyValue(person,
52-
kABPersonLastNameProperty).takeRetainedValue() as String
52+
kABPersonLastNameProperty).takeRetainedValue() as! String
5353

5454
if firstName == paramFirstName &&
5555
lastName == paramLastName{
@@ -69,7 +69,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
6969
for group: ABRecordRef in groups{
7070

7171
let groupName = ABRecordCopyValue(group,
72-
kABGroupNameProperty).takeRetainedValue() as String
72+
kABGroupNameProperty).takeRetainedValue() as! String
7373

7474
if groupName == name{
7575
return true

chapter-basics/Accepting User Text Input with UITextField/Accepting User Text Input with UITextField/ViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@
8686
// func calculateAndDisplayTextFieldLengthWithText(text: String){
8787
//
8888
// var characterOrCharacters = "Character"
89-
// if countElements(text) != 1{
89+
// if count(text) != 1{
9090
// characterOrCharacters += "s"
9191
// }
9292
//
93-
// let stringLength = countElements(text)
93+
// let stringLength = count(text)
9494
//
9595
// label.text = "\(stringLength) \(characterOrCharacters)"
9696
//

chapter-basics/Creating Scrollable Content with UIScrollView/Creating Scrollable Content with UIScrollView/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ViewController: UIViewController, UIScrollViewDelegate {
7070
scrollView.alpha = 1
7171
}
7272

73-
func scrollViewDidEndDragging(scrollView: UIScrollView!,
73+
func scrollViewDidEndDragging(scrollView: UIScrollView,
7474
willDecelerate decelerate: Bool){
7575
scrollView.alpha = 1
7676
}

chapter-basics/Displaying Alerts and Action Sheets/Displaying Alerts and Action Sheets/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ViewController: UIViewController {
8080
handler: {[weak self] (paramAction:UIAlertAction!) in
8181

8282
if let textFields = self!.controller?.textFields{
83-
let theTextFields = textFields as [UITextField]
83+
let theTextFields = textFields as! [UITextField]
8484
let userName = theTextFields[0].text
8585
println("Your username is \(userName)")
8686
}

chapter-basics/Displaying Long Lines of Text with UITextView/Displaying Long Lines of Text with UITextView/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ViewController: UIViewController {
6969

7070
/* Get the frame of the keyboard */
7171
let keyboardRectAsObject =
72-
notification.userInfo![UIKeyboardFrameEndUserInfoKey] as NSValue
72+
notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
7373

7474
/* Place it in a CGRect */
7575
var keyboardRect = CGRectZero

chapter-basics/Displaying Static Text with UILabel/Displaying Static Text with UILabel/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ViewController: UIViewController {
113113

114114
let string = "iOS SDK" as NSString
115115

116-
let result = NSMutableAttributedString(string: string)
116+
let result = NSMutableAttributedString(string: String(string))
117117

118118
let attributesForFirstWord = [
119119
NSFontAttributeName : UIFont.boldSystemFontOfSize(60),

chapter-basics/Grouping Compact Options with UISegmentedControl/Grouping Compact Options with UISegmentedControl/ViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ class ViewController: UIViewController {
134134
override func viewDidLoad() {
135135
super.viewDidLoad()
136136

137-
let segments = NSArray(objects:
137+
let segments = [
138138
"Red",
139139
UIImage(named: "blueDot")!,
140140
"Green",
141-
"Yellow")
141+
"Yellow"]
142142

143143
segmentedControl = UISegmentedControl(items: segments)
144144
segmentedControl.center = view.center

chapter-basics/Loading Web Pages with UIWebView/Loading Web Pages with UIWebView/ViewController.swift

+42-42
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// Vandad Nahavandipoor for his work. Feel free to visit my blog
1111
// at http://vandadnp.wordpress.com for daily tips and tricks in Swift
1212
// and Objective-C and various other programming languages.
13-
//
13+
//
1414
// You can purchase "iOS 8 Swift Programming Cookbook" from
1515
// the following URL:
1616
// http://shop.oreilly.com/product/0636920034254.do
@@ -25,15 +25,15 @@
2525
//import UIKit
2626
//
2727
//class ViewController: UIViewController {
28-
//
28+
//
2929
// override func viewDidLoad() {
3030
// super.viewDidLoad()
31-
//
31+
//
3232
// let webView = UIWebView(frame: view.bounds)
3333
// let htmlString = "<br/>iOS <strong>Programming</strong>"
3434
// webView.loadHTMLString(htmlString, baseURL: nil)
3535
// view.addSubview(webView)
36-
//
36+
//
3737
// }
3838
//
3939
//}
@@ -42,67 +42,67 @@
4242
//import UIKit
4343
//
4444
//class ViewController: UIViewController {
45-
//
45+
//
4646
// /* Hide the status bar to give all the screen real estate */
4747
// override func prefersStatusBarHidden() -> Bool {
4848
// return true
4949
// }
50-
//
50+
//
5151
// override func viewDidLoad() {
5252
// super.viewDidLoad()
53-
//
53+
//
5454
// let webView = UIWebView(frame: view.bounds)
5555
// webView.scalesPageToFit = true
5656
// view.addSubview(webView)
57-
//
57+
//
5858
// let url = NSURL(string: "http://www.apple.com")
5959
// let request = NSURLRequest(URL: url!)
60-
//
60+
//
6161
// webView.loadRequest(request)
62-
//
62+
//
6363
// view.addSubview(webView)
64-
//
64+
//
6565
// }
66-
//
66+
//
6767
//}
6868

6969
/* 3 */
7070
import UIKit
7171

7272
class ViewController: UIViewController, UIWebViewDelegate {
7373

74-
func webViewDidStartLoad(webView: UIWebView!){
75-
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
76-
}
77-
78-
func webViewDidFinishLoad(webView: UIWebView!){
79-
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
80-
}
81-
82-
func webView(webView: UIWebView!, didFailLoadWithError error: NSError!){
83-
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
84-
}
85-
86-
override func viewDidLoad() {
87-
super.viewDidLoad()
88-
89-
/* Render the web view under the status bar */
90-
var frame = view.bounds
91-
frame.origin.y = UIApplication.sharedApplication().statusBarFrame.height
92-
frame.size.height -= frame.origin.y
93-
94-
let webView = UIWebView(frame: frame)
95-
webView.delegate = self
96-
webView.scalesPageToFit = true
97-
view.addSubview(webView)
98-
99-
let url = NSURL(string: "http://www.apple.com")
100-
let request = NSURLRequest(URL: url!)
74+
func webViewDidStartLoad(webView: UIWebView){
75+
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
76+
}
10177

102-
webView.loadRequest(request)
78+
func webViewDidFinishLoad(webView: UIWebView){
79+
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
80+
}
10381

104-
view.addSubview(webView)
82+
func webView(webView: UIWebView, didFailLoadWithError error: NSError){
83+
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
84+
}
10585

106-
}
86+
override func viewDidLoad() {
87+
super.viewDidLoad()
88+
89+
/* Render the web view under the status bar */
90+
var frame = view.bounds
91+
frame.origin.y = UIApplication.sharedApplication().statusBarFrame.height
92+
frame.size.height -= frame.origin.y
93+
94+
let webView = UIWebView(frame: frame)
95+
webView.delegate = self
96+
webView.scalesPageToFit = true
97+
view.addSubview(webView)
98+
99+
let url = NSURL(string: "http://www.apple.com")
100+
let request = NSURLRequest(URL: url!)
101+
102+
webView.loadRequest(request)
103+
104+
view.addSubview(webView)
105+
106+
}
107107

108108
}

chapter-basics/Loading Web Pages with WebKit/Loading Web Pages with WebKit/ViewController.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929
// var webView: WKWebView?
3030
//
3131
// /* Start the network activity indicator when the web view is loading */
32-
// func webView(webView: WKWebView!,
32+
// func webView(webView: WKWebView,
3333
// didStartProvisionalNavigation navigation: WKNavigation!){
3434
// UIApplication.sharedApplication().networkActivityIndicatorVisible = true
3535
// }
3636
//
3737
// /* Stop the network activity indicator when the loading finishes */
38-
// func webView(webView: WKWebView!,
38+
// func webView(webView: WKWebView,
3939
// didFinishNavigation navigation: WKNavigation!){
4040
// UIApplication.sharedApplication().networkActivityIndicatorVisible = false
4141
// }
4242
//
4343
// /* Do not allow links to be tapped */
44-
// func webView(webView: WKWebView!,
44+
// func webView(webView: WKWebView,
4545
// decidePolicyForNavigationAction navigationAction: WKNavigationAction!,
4646
// decisionHandler: ((WKNavigationActionPolicy) -> Void)!){
4747
//
@@ -105,20 +105,20 @@ class ViewController: UIViewController, WKNavigationDelegate {
105105
var webView: WKWebView?
106106

107107
/* Start the network activity indicator when the web view is loading */
108-
func webView(webView: WKWebView!,
109-
didStartProvisionalNavigation navigation: WKNavigation!){
108+
func webView(webView: WKWebView,
109+
didStartProvisionalNavigation navigation: WKNavigation){
110110
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
111111
}
112112

113113
/* Stop the network activity indicator when the loading finishes */
114-
func webView(webView: WKWebView!,
115-
didFinishNavigation navigation: WKNavigation!){
114+
func webView(webView: WKWebView,
115+
didFinishNavigation navigation: WKNavigation){
116116
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
117117
}
118118

119-
func webView(webView: WKWebView!,
120-
decidePolicyForNavigationResponse navigationResponse: WKNavigationResponse!,
121-
decisionHandler: ((WKNavigationResponsePolicy) -> Void)!){
119+
func webView(webView: WKWebView,
120+
decidePolicyForNavigationResponse navigationResponse: WKNavigationResponse,
121+
decisionHandler: ((WKNavigationResponsePolicy) -> Void)){
122122

123123
println(navigationResponse.response.MIMEType)
124124

chapter-basics/Presenting Custom Sharing Options with UIActivityViewController/Presenting Custom Sharing Options with UIActivityViewController/StringReverserActivity.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ class StringReverserActivity: UIActivity {
3232
*/
3333
var activityItems = [NSString]()
3434

35-
func reverseOfString(string: NSString) -> NSString{
35+
func reverseOfString(string: String) -> String{
3636

3737
var result = ""
3838
var characters = [Character]()
3939

40-
for character in string as String{
40+
for character in string{
4141
characters.append(character)
4242
}
4343

@@ -54,7 +54,7 @@ class StringReverserActivity: UIActivity {
5454
var reversedStrings = ""
5555

5656
for string in activityItems{
57-
reversedStrings += reverseOfString(string) + "\n"
57+
reversedStrings += reverseOfString(String(string)) + "\n"
5858
}
5959

6060
/* Do whatever that you need to do, with all these
@@ -91,8 +91,8 @@ class StringReverserActivity: UIActivity {
9191
override func prepareWithActivityItems(paramActivityItems: [AnyObject]) {
9292

9393
for object:AnyObject in paramActivityItems{
94-
if object is NSString{
95-
activityItems.append(object as NSString)
94+
if object is String{
95+
activityItems.append(NSString(string: object as! String))
9696
}
9797
}
9898

chapter-basics/Presenting Sharing Options with UIActivityViewController/Presenting Sharing Options with UIActivityViewController/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ViewController: UIViewController, UITextFieldDelegate {
9696
})
9797
}
9898

99-
func textFieldShouldReturn(textField: UITextField!) -> Bool{
99+
func textFieldShouldReturn(textField: UITextField) -> Bool{
100100
textField.resignFirstResponder()
101101
return true
102102
}

0 commit comments

Comments
 (0)