Skip to content

Commit 98b4e7a

Browse files
committed
more #selector-related tweaks
1 parent 13eb19a commit 98b4e7a

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

bk2ch08p454tableCellMenus2/ch21p718sections/MyCell.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ class MyCell : UITableViewCell {
1212
// ask it what index path we are
1313
let ip = tv.indexPathForCell(self)!
1414
// talk to its delegate
15-
let action = Selector(#function + ":") // work around weird way Swift expresses this
16-
tv.delegate?.tableView?(tv, performAction:action, forRowAtIndexPath:ip, withSender:sender)
15+
tv.delegate?.tableView?(tv, performAction:#selector(abbrev), forRowAtIndexPath:ip, withSender:sender)
1716
}
1817

1918
}

bk2ch08p454tableCellMenus2/ch21p718sections/RootViewController.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ class RootViewController : UITableViewController {
104104

105105
// menu handling ==========
106106

107-
// NB Swift 2.2 doesn't seem able to resolve #selector(abbrev(_:))
108-
// without our telling it what class it's in
109-
// I'm not sure I like this, since it means this class can't be agnostic about it
110-
111107
override func tableView(tableView: UITableView, shouldShowMenuForRowAtIndexPath indexPath: NSIndexPath) -> Bool {
112108
let mi = UIMenuItem(title: "Abbrev", action: #selector(MyCell.abbrev))
113109
UIMenuController.sharedMenuController().menuItems = [mi]

bk2ch08p454tableCellMenus2/ch21p746tableCellMenus2.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@
437437
CLANG_ENABLE_MODULES = YES;
438438
GCC_PRECOMPILE_PREFIX_HEADER = YES;
439439
GCC_PREFIX_HEADER = "";
440+
GCC_WARN_UNDECLARED_SELECTOR = YES;
440441
INFOPLIST_FILE = "ch21p718sections/ch21p746tableCellMenus2-Info.plist";
441442
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
442443
ONLY_ACTIVE_ARCH = NO;
@@ -454,6 +455,7 @@
454455
CLANG_ENABLE_MODULES = YES;
455456
GCC_PRECOMPILE_PREFIX_HEADER = YES;
456457
GCC_PREFIX_HEADER = "";
458+
GCC_WARN_UNDECLARED_SELECTOR = YES;
457459
INFOPLIST_FILE = "ch21p718sections/ch21p746tableCellMenus2-Info.plist";
458460
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
459461
ONLY_ACTIVE_ARCH = NO;

bk2ch08p466collectionViewFlowLayout2/ch21p748collectionViewFlowLayout2/Cell.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class Cell : UICollectionViewCell {
1414
// ask it what index path we are
1515
let ip = cv.indexPathForCell(self)!
1616
// relay to its delegate
17-
let action = Selector(#function + ":")
18-
cv.delegate?.collectionView?(cv, performAction:action, forItemAtIndexPath: ip, withSender: sender)
17+
cv.delegate?.collectionView?(cv, performAction:#selector(capital), forItemAtIndexPath: ip, withSender: sender)
1918
}
2019
}
2120

bk2ch08p466collectionViewFlowLayout2/ch21p748collectionViewFlowLayout2/ViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ class ViewController : UICollectionViewController, UICollectionViewDelegateFlowL
209209
if arr.count == 0 {
210210
return
211211
}
212-
// sort [NB I don't understand why compare(_:) can't be resolved without more info
213-
let arr2 = ((arr as NSArray).sortedArrayUsingSelector(#selector(NSString.compare(_:))) as! [NSIndexPath])
212+
// sort
213+
let arr2 = ((arr as NSArray).sortedArrayUsingSelector(#selector(NSIndexPath.compare(_:))) as! [NSIndexPath])
214214
// delete data
215215
var empties = [Int]() // keep track of what sections get emptied
216216
for ip in arr2.reverse() {
@@ -238,7 +238,6 @@ class ViewController : UICollectionViewController, UICollectionViewDelegateFlowL
238238
// menu =================
239239

240240
// exactly as for table views
241-
// NB As in the table view example, we have to help Swift resolve capital(_:)
242241

243242
override func collectionView(collectionView: UICollectionView, shouldShowMenuForItemAtIndexPath indexPath: NSIndexPath) -> Bool {
244243
let mi = UIMenuItem(title:"Capital", action:#selector(Cell.capital))

bk2ch10p526textFieldDelegate/ch23p810textFieldDelegate/Base.lproj/Main.storyboard

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8187.4" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10115" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
33
<dependencies>
4-
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8151.3"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10084"/>
65
</dependencies>
76
<scenes>
87
<!--View Controller-->
@@ -22,7 +21,6 @@
2221
<fontDescription key="fontDescription" type="system" pointSize="14"/>
2322
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no"/>
2423
<connections>
25-
<action selector="dummy:" destination="x5A-6p-PRh" eventType="editingDidEndOnExit" id="mNh-vJ-hUA"/>
2624
<outlet property="delegate" destination="vXZ-lx-hvc" id="VEc-FJ-OkH"/>
2725
</connections>
2826
</textField>

bk2ch10p526textFieldDelegate/ch23p810textFieldDelegate/MyTextField.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import UIKit
55

66
class MyTextField: UITextField {
77

8+
// make self-dismissing; can do this without code, but just testing
9+
required init?(coder aDecoder: NSCoder) {
10+
super.init(coder:aDecoder)
11+
self.addTarget(
12+
nil, action:Selector("dummy:"), forControlEvents:.EditingDidEndOnExit)
13+
}
14+
15+
// func dummy(_:AnyObject) {}
16+
817
let list : [String] = {
918
let path = NSBundle.mainBundle().URLForResource("abbreviations", withExtension:"txt")!
1019
let s = try! String(contentsOfURL:path, encoding:NSUTF8StringEncoding)

0 commit comments

Comments
 (0)