帮助解决这个快速3错误。我们试图以某种方式存储每个短语中的字符数,在这种情况下,根据来自https://www.raywenderlich.com/77981/make-letter-word-game-uikit-swift-part-1的源来存储anagram1length和anagram2length。这里关注的是swift 3中的以下两行代码,错误地使用了未解析的标识符'count':
let anagram1length = count(anagram1)
let anagram2length = count(anagram2)
从以下功能:
func dealRandomAnagram () {
//1
assert(level.anagrams.count > 0, "no level loaded")
//2
let randomIndex = randomNumber(minX:0, maxX:UInt32(level.anagrams.count-1))
let anagramPair = level.anagrams[randomIndex]
//3
let anagram1 = anagramPair[0] as! String
let anagram2 = anagramPair[1] as! String
//4
let anagram1length = count(anagram1)
let anagram2length = count(anagram2)
//5
print("phrase1[\(anagram1length)]: \(anagram1)")
print("phrase2[\(anagram2length)]: \(anagram2)")
//calculate the tile size
let tileSide = ceil(ScreenWidth * 0.9 / CGFloat(max(anagram1length, anagram2length))) - TileMargin
//get the left margin for first tile
var xOffset = (ScreenWidth - CGFloat(max(anagram1length, anagram2length)) * (tileSide + TileMargin)) / 2.0
//adjust for tile center (instead of the tile's origin)
xOffset += tileSide / 2.0
//initialize target list
targets = []
//create targets
for (index, letter) in anagram2length.enumerate(anagram2) {
if letter != " " {
let target = TargetView(letter: letter, sideLength: tileSide)
target.center = CGPointMake(xOffset + CGFloat(index)*(tileSide + TileMargin), ScreenHeight/4)
gameView.addSubview(target)
targets.append(target)
}
}
答案 0 :(得分:1)
本教程显然是用旧的Swift版本编写的。
在当前的Swift 3版本中,它通常是
let anagram1length = anagram1.characters.count
let anagram2length = anagram2.characters.count