Skip to content

Commit f69fe4b

Browse files
committed
eliminated a couple more var params
1 parent 12ca9aa commit f69fe4b

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

bk1ch02p038modifiableParameters/bk1ch02p038modifiableParameters/ViewController.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22

33
import UIKit
44

5-
// WARNING: This may go away, because it is, after all, rather misleading
6-
5+
// This will go away, because it is, after all, rather misleading
6+
/*
77
func say(s:String, times:Int, var loudly:Bool) {
88
loudly = true // can't do this without "var"
99
}
10+
*/
11+
12+
// instead, write this:
13+
14+
func say(s:String, times:Int, loudly:Bool) {
15+
var loudly = loudly
16+
loudly = true
17+
_ = loudly
18+
}
1019

11-
// WARNING: This may go away, because it is, after all, rather misleading
1220

21+
// This will go away, because it is, after all, rather misleading
22+
/*
1323
func removeFromStringNot(var s:String, character c:Character) -> Int {
1424
var howMany = 0
1525
while let ix = s.characters.indexOf(c) {
@@ -18,6 +28,20 @@ func removeFromStringNot(var s:String, character c:Character) -> Int {
1828
}
1929
return howMany
2030
}
31+
*/
32+
33+
// instead, write this:
34+
35+
func removeFromStringNot(s:String, character c:Character) -> Int {
36+
var s = s
37+
var howMany = 0
38+
while let ix = s.characters.indexOf(c) {
39+
s.removeRange(ix...ix)
40+
howMany += 1
41+
}
42+
return howMany
43+
}
44+
2145

2246

2347
func removeFromString(inout s:String, character c:Character) -> Int {

0 commit comments

Comments
 (0)