Skip to content

Commit f89ece7

Browse files
committed
Updated all the example codes for Xcode 6.1 (6A1052d)
1 parent 63bd0ac commit f89ece7

File tree

100 files changed

+612
-608
lines changed

Some content is hidden

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

100 files changed

+612
-608
lines changed

chapter-addressBook/Requesting Access to the Address Book/Requesting Access to the Address Book/AppDelegate.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4141
}
4242

4343
func application(application: UIApplication!,
44-
didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
44+
didFinishLaunchingWithOptions launchOptions:
45+
[NSObject : AnyObject]?) -> Bool {
4546

4647
switch ABAddressBookGetAuthorizationStatus(){
4748
case .Authorized:

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ ABPeoplePickerNavigationControllerDelegate {
6161
let address: NSDictionary = ABMultiValueCopyValueAtIndex(addresses,
6262
index).takeRetainedValue() as NSDictionary
6363

64-
println("Country = \(address[kABPersonAddressCountryKey])")
65-
println("City = \(address[kABPersonAddressCityKey])")
66-
println("Street = \(address[kABPersonAddressStreetKey])")
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
67+
68+
println("Country = \(country)")
69+
println("City = \(city)")
70+
println("Street = \(street)")
6771

6872
}
6973

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

+3-3
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 = [
137+
let segments = NSArray(objects:
138138
"Red",
139-
UIImage(named: "blueDot"),
139+
UIImage(named: "blueDot")!,
140140
"Green",
141-
"Yellow"]
141+
"Yellow")
142142

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

chapter-basics/Introduction to Chapter (Basics)/Introduction to Chapter (Basics)/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ViewController: UIViewController {
3232
}
3333

3434
func example2(){
35-
let integerFromDouble: Int = 10.7
35+
let integerFromDouble = 10.7 as Int
3636
/* The value of this variable is 10
3737
because the compiler truncated the value to an integer*/
3838
}

chapter-basics/Jumping Right Into Swift/Jumping Right Into Swift/AppDelegate.swift

+55-55
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,32 @@ import UIKit
7070
//
7171
//}
7272

73-
//enum CarClassification: String{
74-
// case Estate = "Estate"
75-
// case Hatchback = "Hatchback"
76-
// case Saloon = "Saloon"
77-
//}
78-
//
79-
//struct Car{
80-
// let classification: CarClassification
81-
//}
82-
//
83-
//@UIApplicationMain
84-
//class AppDelegate: UIResponder, UIApplicationDelegate {
85-
//
86-
// var window: UIWindow?
87-
//
88-
// func application(application: UIApplication,
89-
// didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
90-
//
91-
// if let classification = CarClassification.fromRaw("Estate"){
92-
// let volvoV50 = Car(classification: classification)
93-
// }
94-
//
95-
// return true
96-
// }
97-
//
98-
//}
73+
enum CarClassification: String{
74+
case Estate = "Estate"
75+
case Hatchback = "Hatchback"
76+
case Saloon = "Saloon"
77+
}
78+
79+
struct Car{
80+
let classification: CarClassification
81+
}
82+
83+
@UIApplicationMain
84+
class AppDelegate: UIResponder, UIApplicationDelegate {
85+
86+
var window: UIWindow?
87+
88+
func application(application: UIApplication,
89+
didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
90+
91+
if let classification = CarClassification(rawValue: "Estate"){
92+
let volvoV50 = Car(classification: classification)
93+
}
94+
95+
return true
96+
}
97+
98+
}
9999

100100
//class Person{
101101
// var age: Int
@@ -253,7 +253,7 @@ import UIKit
253253
// }
254254
//
255255
//}
256-
//
256+
257257
//@UIApplicationMain
258258
//class AppDelegate: UIResponder, UIApplicationDelegate {
259259
//
@@ -276,35 +276,35 @@ import UIKit
276276
//
277277
//}
278278

279-
@UIApplicationMain
280-
class AppDelegate: UIResponder, UIApplicationDelegate {
281-
282-
var window: UIWindow?
283-
284-
func application(application: UIApplication!,
285-
didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
286-
279+
//@UIApplicationMain
280+
//class AppDelegate: UIResponder, UIApplicationDelegate {
281+
//
282+
// var window: UIWindow?
283+
//
284+
// func application(application: UIApplication!,
285+
// didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
286+
//
287287
// let integerValue = 10
288288
// let stringValue = "Swift"
289289
// let doubleValue = 10.0
290-
291-
let integerFromDouble: Int = 10.7
292-
/* The value of this variable is 10
293-
since the compiler truncated the value to an integer*/
294-
295-
290+
//
291+
// let integerFromDouble = 10.7 as Int
292+
// /* The value of this variable is 10
293+
// since the compiler truncated the value to an integer*/
294+
//
295+
//
296296
// var myString = "Swi"
297297
// myString += "ft"
298-
// /* myString is now "Swift" */
299-
298+
// /* myString is now "Swift" */
299+
//
300300
// let allStrings = ["Swift", "Objective-C"]
301-
301+
//
302302
// var allStrings = [String]()
303303
// allStrings.append("Swift")
304304
// allStrings.append("Objective-C")
305305
// /* Our array is now ["Swift", "Objective-C"] */
306-
307-
306+
//
307+
//
308308
// var allStrings = [String]()
309309
// allStrings.append("Swift")
310310
// allStrings.append("Objective-C")
@@ -314,33 +314,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
314314
// allStrings.insert("C++", atIndex: 0)
315315
//
316316
// println(allStrings[0]) /* Prints out "C++" */
317-
317+
//
318318
// let allFullNames = [
319319
// "Vandad" : "Nahavandipoor",
320320
// "Andy" : "Oram",
321321
// "Molly" : "Lindstedt"
322322
// ]
323323
//
324324
// println(allFullNames["Vandad"]) /* Prints out "Nahavandipoor" */
325-
326-
325+
//
326+
//
327327
// var allFullNames = [
328328
// "Vandad" : "Nahavandipoor",
329329
// "Andy" : "Oram",
330330
// "Molly" : "Lindstedt"
331331
// ]
332332
//
333333
// allFullNames["Rachel"] = "Roumeliotis"
334-
334+
//
335335
// let personInformation = [
336336
// "numberOfChildren" : 2,
337337
// "age" : 32,
338338
// "name" : "Random person",
339339
// "job" : "Something cool",
340340
// ] as [String : AnyObject]
341-
342-
return true
343-
}
344-
345-
}
341+
//
342+
// return true
343+
// }
344+
//
345+
//}
346346

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
// view.addSubview(webView)
5757
//
5858
// let url = NSURL(string: "http://www.apple.com")
59-
// let request = NSURLRequest(URL: url)
59+
// let request = NSURLRequest(URL: url!)
6060
//
6161
// webView.loadRequest(request)
6262
//
@@ -97,7 +97,7 @@ override func viewDidLoad() {
9797
view.addSubview(webView)
9898

9999
let url = NSURL(string: "http://www.apple.com")
100-
let request = NSURLRequest(URL: url)
100+
let request = NSURLRequest(URL: url!)
101101

102102
webView.loadRequest(request)
103103

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
// if let theWebView = webView{
8787
// /* Load a web page into our web view */
8888
// let url = NSURL(string: "http://www.apple.com")
89-
// let urlRequest = NSURLRequest(URL: url)
89+
// let urlRequest = NSURLRequest(URL: url!)
9090
// theWebView.loadRequest(urlRequest)
9191
// theWebView.navigationDelegate = self
9292
// view.addSubview(theWebView)
@@ -143,7 +143,7 @@ class ViewController: UIViewController, WKNavigationDelegate {
143143
if let theWebView = webView{
144144
/* Load a web page into our web view */
145145
let url = NSURL(string: "http://www.apple.com")
146-
let urlRequest = NSURLRequest(URL: url)
146+
let urlRequest = NSURLRequest(URL: url!)
147147
theWebView.loadRequest(urlRequest)
148148
theWebView.navigationDelegate = self
149149
view.addSubview(theWebView)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class StringReverserActivity: UIActivity {
7272
}
7373

7474
override func activityImage() -> UIImage {
75-
return UIImage(named: "Reverse")
75+
return UIImage(named: "Reverse")!
7676
}
7777

7878
override func canPerformWithActivityItems(

chapter-basics/Presenting Temporary Information on the Screen with Popovers/Presenting Temporary Information on the Screen with Popovers/PopoverTableViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class PopoverTableViewController: UITableViewController {
105105
let cell = tableView.dequeueReusableCellWithIdentifier(
106106
TableViewValues.identifier, forIndexPath: indexPath) as UITableViewCell
107107

108-
cell.textLabel!.text = items[indexPath]
108+
cell.textLabel.text = items[indexPath]
109109

110110
return cell
111111

chapter-camera/Taking Videos with the Camera/Taking Videos with the Camera/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ UINavigationControllerDelegate, UIImagePickerControllerDelegate {
5656
options: .MappedRead,
5757
error: &dataReadingError)
5858

59-
if videoData.length == 0{
59+
if videoData!.length == 0{
6060
/* We were able to read the data */
6161
println("Successfully loaded the data")
6262
} else {

chapter-cloud/Creating and Managing Folders for Apps in iCloud/Creating and Managing Folders for Apps in iCloud/AppDelegate.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
// }
5656
//
5757
// func application(application: UIApplication!,
58-
// didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
58+
// didFinishLaunchingWithOptions launchOptions:
59+
// [NSObject : AnyObject]?) -> Bool {
5960
//
6061
// let containerURL =
6162
// fileManager.URLForUbiquityContainerIdentifier(nil)
@@ -152,7 +153,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
152153
}
153154

154155
func application(application: UIApplication!,
155-
didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
156+
didFinishLaunchingWithOptions launchOptions:
157+
[NSObject : AnyObject]?) -> Bool {
156158

157159
let containerURL =
158160
fileManager.URLForUbiquityContainerIdentifier(nil)

chapter-cloud/Observing Changes to Records in CloudKit/Observing Changes to Records in CloudKit/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ViewController: UIViewController {
116116
[weak self] (subscription: CKSubscription!, error: NSError!) in
117117

118118
if error != nil{
119-
if CKErrorCode.fromRaw(error.code)! == .UnknownItem{
119+
if error.code == CKErrorCode.UnknownItem.rawValue{
120120
println("This subscription doesn't exist. Creating it now...")
121121

122122
self!.database.saveSubscription(self!.subscription(),

chapter-cloud/Querying the Cloud with CloudKit/Querying the Cloud with CloudKit/ViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
// case Estate = "Estate"
6868
//
6969
// func zoneId() -> CKRecordZoneID{
70-
// let zoneId = CKRecordZoneID(zoneName: self.toRaw(),
70+
// let zoneId = CKRecordZoneID(zoneName: self.rawValue,
7171
// ownerName: CKOwnerDefaultName)
7272
// return zoneId
7373
// }
@@ -147,7 +147,7 @@ class ViewController: UIViewController {
147147
case Estate = "Estate"
148148

149149
func zoneId() -> CKRecordZoneID{
150-
let zoneId = CKRecordZoneID(zoneName: self.toRaw(),
150+
let zoneId = CKRecordZoneID(zoneName: self.rawValue,
151151
ownerName: CKOwnerDefaultName)
152152
return zoneId
153153
}

chapter-cloud/Retrieving Data with CloudKit/Retrieving Data with CloudKit/ViewController.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ViewController: UIViewController {
1818
case Estate = "Estate"
1919

2020
func zoneId() -> CKRecordZoneID{
21-
let zoneId = CKRecordZoneID(zoneName: self.toRaw(),
21+
let zoneId = CKRecordZoneID(zoneName: self.rawValue,
2222
ownerName: CKOwnerDefaultName)
2323
return zoneId
2424
}
@@ -104,7 +104,7 @@ class ViewController: UIViewController {
104104
// if error != nil{
105105
// println("An error occurred")
106106
//
107-
// if error.code == CKErrorCode.UnknownItem.toRaw(){
107+
// if error.code == CKErrorCode.UnknownItem.rawValue{
108108
// println("This error means that the record was not found.")
109109
// println("Saving the record...")
110110
//
@@ -169,7 +169,7 @@ class ViewController: UIViewController {
169169
if error != nil{
170170
println("An error occurred")
171171

172-
if error.code == CKErrorCode.UnknownItem.toRaw(){
172+
if error.code == CKErrorCode.UnknownItem.rawValue{
173173
println("This error means that the record was not found.")
174174
println("Saving the record...")
175175

@@ -194,7 +194,7 @@ class ViewController: UIViewController {
194194

195195
/* Now make your changes to the record */
196196
let colorKey = "color"
197-
let newColor = Color.randomColor().toRaw()
197+
let newColor = Color.randomColor().rawValue
198198
var oldColor = record.valueForKey(colorKey) as? String
199199
if oldColor == nil{
200200
oldColor = "Unknown"

0 commit comments

Comments
 (0)