Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b942a76

Browse files
committed
Fixed very minor .characters deprecations on String
1 parent 6bd8af5 commit b942a76

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

‎Classic Computer Science Problems in Swift.playground/Pages/Chapter 1.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ struct CompressedGene {
7474
private let bitVector: CFMutableBitVector
7575

7676
init(original: String) {
77-
length = original.characters.count
77+
length = original.count
7878
// default allocator, need 2 * length number of bits
7979
bitVector = CFBitVectorCreateMutable(kCFAllocatorDefault, length * 2)
8080
CFBitVectorSetCount(bitVector, length * 2) // fills the bit vector with 0s
8181
compress(gene: original)
8282
}
8383

8484
private func compress(gene: String) {
85-
for (index, nucleotide) in gene.uppercased().characters.enumerated() {
85+
for (index, nucleotide) in gene.uppercased().enumerated() {
8686
let nStart = index * 2 // start of each new nucleotide
8787
switch nucleotide {
8888
case "A": // 00

‎Classic Computer Science Problems in Swift.playground/Pages/Chapter 2.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ let geneSequence = "ACGTGGCTCTCTAACGTACGTACGTACGGGGTTTATATATACCCTAGGACTCCCTTT"
5050

5151
func stringToGene(_ s: String) -> Gene {
5252
var gene = Gene()
53-
for i in stride(from: 0, to: s.characters.count, by: 3) {
54-
guard (i + 2) < s.characters.count else { return gene }
53+
for i in stride(from: 0, to: s.count, by: 3) {
54+
guard (i + 2) < s.count else { return gene }
5555
if let n1 = Nucleotide.init(rawValue: s[s.index(s.startIndex, offsetBy: i)]), let n2 = Nucleotide.init(rawValue: s[s.index(s.startIndex, offsetBy: i + 1)]), let n3 = Nucleotide.init(rawValue: s[s.index(s.startIndex, offsetBy: i + 2)]) {
5656
gene.append((n1, n2, n3))
5757
}

‎Classic Computer Science Problems in Swift.playground/Pages/Chapter 3.xcplaygroundpage/Contents.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func generateGrid(rows: Int, columns: Int) -> Grid {
213213
// replace spaces with random letters
214214
for row in 0..<rows {
215215
for col in 0..<columns {
216-
let loc = ALPHABET.index(ALPHABET.startIndex, offsetBy: Int(arc4random_uniform(UInt32(ALPHABET.characters.count))))
216+
let loc = ALPHABET.index(ALPHABET.startIndex, offsetBy: Int(arc4random_uniform(UInt32(ALPHABET.count))))
217217
grid[row][col] = ALPHABET[loc]
218218
}
219219
}
@@ -234,7 +234,7 @@ func generateDomain(word: String, grid: Grid) -> [[GridLocation]] {
234234
var domain: [[GridLocation]] = [[GridLocation]]()
235235
let height = grid.count
236236
let width = grid[0].count
237-
let wordLength = word.characters.count
237+
let wordLength = word.count
238238
for row in 0..<height {
239239
for col in 0..<width {
240240
let columns = col...(col + wordLength)
@@ -293,7 +293,7 @@ wordsearch.addConstraint(WordSearchConstraint(words: words))
293293
if let solution = backtrackingSearch(csp: wordsearch) {
294294
for (word, gridLocations) in solution {
295295
let gridLocs = arc4random_uniform(2) > 0 ? gridLocations : gridLocations.reversed() // randomly reverse word half the time
296-
for (index, letter) in word.characters.enumerated() {
296+
for (index, letter) in word.enumerated() {
297297
let (row, col) = (gridLocs[index].row, gridLocations[index].col)
298298
grid[row][col] = letter
299299
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /