Skip to content

Commit a63f3da

Browse files
committed
update for Swift 1.2, Xcode 6.3
1 parent e4528cc commit a63f3da

File tree

10 files changed

+38
-27
lines changed

10 files changed

+38
-27
lines changed

bk2ch12p582datePicker/bk2ch12p582datePicker/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ViewController: UIViewController {
1515
super.viewDidLoad()
1616
// Do any additional setup after loading the view, typically from a nib.
1717

18-
let which = 2
18+
let which = 1
1919
switch which {
2020
case 1:
2121
dp.datePickerMode = .Date

bk2ch13p620dialogsOniPhone/ch26p888dialogsOniPhone/ViewController.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ class ViewController: UIViewController {
3939
}
4040
func handler(act:UIAlertAction!) {
4141
// it's a closure so we have a reference to the alert
42-
let tf = alert.textFields![0] as UITextField
42+
let tf = alert.textFields![0] as! UITextField
4343
println("User entered \(tf.text), tapped \(act.title)")
4444
}
4545
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
4646
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: handler))
47-
(alert.actions[1] as UIAlertAction).enabled = false
47+
(alert.actions[1] as! UIAlertAction).enabled = false
4848
self.presentViewController(alert, animated: true, completion: nil)
4949
}
5050

5151
func textChanged(sender:AnyObject) {
52-
let tf = sender as UITextField
52+
let tf = sender as! UITextField
5353
// enable OK button only if there is text
5454
// hold my beer and watch this: how to get a reference to the alert
5555
var resp : UIResponder! = tf
5656
while !(resp is UIAlertController) { resp = resp.nextResponder() }
57-
let alert = resp as UIAlertController
58-
(alert.actions[1] as UIAlertAction).enabled = (tf.text != "")
57+
let alert = resp as! UIAlertController
58+
(alert.actions[1] as! UIAlertAction).enabled = (tf.text != "")
5959
}
6060

6161
// =====
@@ -74,7 +74,7 @@ class ViewController: UIViewController {
7474
// v.hidden = true
7575
// }
7676
if let pop = action.popoverPresentationController {
77-
let v = sender as UIView
77+
let v = sender as! UIView
7878
pop.sourceView = v
7979
pop.sourceRect = v.bounds
8080
}

bk2ch13p624actionSheetPopovers/ch26p892actionSheetPopovers/PopoverViewController.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ class PopoverViewController: UIViewController {
1010

1111
@IBAction func showOptions(sender:AnyObject) {
1212
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
13-
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
14-
alert.addAction(UIAlertAction(title: "Hey", style: .Default, handler: nil))
15-
alert.addAction(UIAlertAction(title: "Ho", style: .Default, handler: nil))
16-
alert.addAction(UIAlertAction(title: "Hey Nonny No", style: .Default, handler: nil))
13+
func handler(act:UIAlertAction!) {
14+
println("User tapped \(act.title)")
15+
}
16+
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: handler))
17+
alert.addAction(UIAlertAction(title: "Hey", style: .Default, handler: handler))
18+
alert.addAction(UIAlertAction(title: "Ho", style: .Default, handler: handler))
19+
alert.addAction(UIAlertAction(title: "Hey Nonny No", style: .Default, handler: handler))
1720
// .OverCurrentContext is the default, so no need to specify! just show it
1821
self.presentViewController(alert, animated: true, completion: nil)
1922
// tapping outside the sheet but inside the containing popover dismisses the sheet
2023
// tapping outside the containing popover dismisses the popover
2124
// to prevent that, you have to take charge of dismissal
25+
// No, the above is fixed in iOS 8.3
2226
}
2327

2428
}

bk2ch13p624actionSheetPopovers/ch26p892actionSheetPopovers/ViewController.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ class ViewController: UIViewController {
1616

1717
@IBAction func doButton(sender:AnyObject) {
1818
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
19-
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)) // not shown
20-
alert.addAction(UIAlertAction(title: "Hey", style: .Default, handler: nil))
21-
alert.addAction(UIAlertAction(title: "Ho", style: .Default, handler: nil))
22-
alert.addAction(UIAlertAction(title: "Hey Nonny No", style: .Default, handler: nil))
19+
func handler(act:UIAlertAction!) {
20+
println("User tapped \(act.title)")
21+
}
22+
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: handler)) // not shown
23+
alert.addAction(UIAlertAction(title: "Hey", style: .Default, handler: handler))
24+
alert.addAction(UIAlertAction(title: "Ho", style: .Default, handler: handler))
25+
alert.addAction(UIAlertAction(title: "Hey Nonny No", style: .Default, handler: handler))
2326
self.presentViewController(alert, animated: true, completion: nil)
2427
// if we do no more than that, we'll crash with a helpful error message:
2528
// "UIPopoverPresentationController should have a non-nil sourceView or barButtonItem set before the presentation occurs"
2629
// so the runtime knows that on iPad this should be a popover, and has arranged it already
2730
// all we have to do is fulfill our usual popover responsibilities
2831
if let pop = alert.popoverPresentationController {
29-
pop.barButtonItem = sender as UIBarButtonItem
32+
pop.barButtonItem = sender as! UIBarButtonItem
3033
// but now we have the usual foo where we must prevent the bar button items
3134
// from being "live"; why isn't this automatic???
3235
// still, it isn't anywhere near as bad as in previous systems
@@ -41,8 +44,8 @@ class ViewController: UIViewController {
4144
pvc.modalPresentationStyle = .Popover
4245
self.presentViewController(pvc, animated: true, completion: nil)
4346
if let pop = pvc.popoverPresentationController {
44-
pop.barButtonItem = sender as UIBarButtonItem
45-
pop.delegate = self
47+
pop.barButtonItem = sender as! UIBarButtonItem
48+
//pop.delegate = self
4649
delay(0.1) {
4750
pop.passthroughViews = nil
4851
}
@@ -51,13 +54,17 @@ class ViewController: UIViewController {
5154

5255
}
5356

57+
// not needed in iOS 8.3
58+
59+
/*
5460
extension ViewController : UIPopoverPresentationControllerDelegate {
5561
func popoverPresentationControllerShouldDismissPopover(
5662
pop: UIPopoverPresentationController) -> Bool {
5763
let ok = pop.presentedViewController.presentedViewController == nil
5864
return ok
5965
}
6066
}
67+
*/
6168

6269
extension ViewController : UIToolbarDelegate {
6370
func positionForBar(bar: UIBarPositioning) -> UIBarPosition {

bk2ch13p630localNotification/ch26p899localNotification/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class AppDelegate : UIResponder, UIApplicationDelegate {
6060
// if .Background, should also set authenticationRequired to say what to do from lock screen
6161

6262
category.setActions([action1, action2], forContext: .Default) // can have 4 for default, 2 for minimal
63-
let settings = UIUserNotificationSettings(forTypes: types, categories: NSSet(array: [category]))
63+
let settings = UIUserNotificationSettings(forTypes: types, categories: Set([category]))
6464
application.registerUserNotificationSettings(settings)
6565
// if this app has never requested this registration,
6666
// it will put up a dialog asking if we can present alerts etc.

bk2ch13p631todayExtension/CoffeeTimeTodayExtension/TodayViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TodayViewController: UIViewController, NCWidgetProviding {
2727

2828
@IBAction func doButton(sender: AnyObject) {
2929
NSLog("doButton")
30-
let v = sender as UIView
30+
let v = sender as! UIView
3131
let t = v.tag // tag is number of minutes
3232
if let url = NSURL(string:"coffeetime://\(String(t))") {
3333
NSLog("%@", "\(url)")

bk2ch13p635activityView/ch26p901activityView/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ViewController: UIViewController {
2929
self.presentViewController(avc, animated:true, completion:nil)
3030
// on iPad this will be an action sheet and will need a source view or bar button item
3131
if let pop = avc.popoverPresentationController {
32-
let v = sender as UIView
32+
let v = sender as! UIView
3333
pop.sourceView = v
3434
pop.sourceRect = v.bounds
3535
}

bk2ch13p636actionExtension/Expand/ActionRequestHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ class ActionRequestHandler: NSObject /*, NSExtensionRequestHandling */ { // ???
88
let list : [String] = {
99
let path = NSBundle.mainBundle().URLForResource("abbreviations", withExtension:"txt")!
1010
let s = String(contentsOfURL:path, encoding:NSUTF8StringEncoding, error:nil)!
11-
return s.componentsSeparatedByString("\n") as [String]
11+
return s.componentsSeparatedByString("\n")
1212
}()
1313

1414
var extensionContext: NSExtensionContext?
1515
// NSObject has no magically acquired extension context, we must keep a reference
1616

17-
let desiredType = kUTTypePlainText
17+
let desiredType = kUTTypePlainText as String
1818

1919
func beginRequestWithExtensionContext(context: NSExtensionContext!) {
2020
// Do not call super in an Action extension with no user interface

bk2ch13p636actionExtension/Expand2/ActionViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class ActionViewController: UIViewController {
88

99
let list : [String] = {
1010
let path = NSBundle.mainBundle().URLForResource("abbreviations", withExtension:"txt")!
11-
let s = NSString(contentsOfURL:path, encoding:NSUTF8StringEncoding, error:nil)!
12-
return s.componentsSeparatedByString("\n") as [String]
11+
let s = String(contentsOfURL:path, encoding:NSUTF8StringEncoding, error:nil)!
12+
return s.componentsSeparatedByString("\n")
1313
}()
1414

15-
let desiredType = kUTTypePlainText as NSString
15+
let desiredType = kUTTypePlainText as String
1616
var orig : String?
1717
var abbrev : String?
1818

bk2ch13p636actionExtension/ch23p810textFieldDelegate/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func delay(delay:Double, closure:()->()) {
1414
class ViewController: UIViewController, UITextFieldDelegate {
1515

1616
@IBOutlet var tf : UITextField!
17-
let desiredType = kUTTypePlainText as NSString
17+
let desiredType = kUTTypePlainText as String
1818

1919
override func viewDidLoad() {
2020
super.viewDidLoad()

0 commit comments

Comments
 (0)