Use of unresolved identifier 'find'

Thanks in advance for the help!

Using Xcode 9.3.


I'm getting a “Use of unresolved identifier ‘find’” error in the rowCheck function.

Here’s my code:


func rowCheck(_ value: Int) -> (location:String, pattern: String)? {

var acceptableFinds = ["011","110","101"]

var findFuncs = [checkTop, checkBottom, checkLeft, checkRight, checkMiddleAcross, checkMiddleDown, checkDiagLeftRight, checkDiagRightLeft]

for algorthm in findFuncs{

var algorthmResults = algorthm(value)

if find(acceptableFinds,algorthmResults.pattern){

return algorthmResults

}

}

}

Answered by OOPer in 304238022

Do you really want to solve your issue? You have ignored some of my askings:

In what class does your `find(_:_:)` is defined?

And one more, please use code insertion feature of this site. Jus click the icon `<>`.


If you have found an old Swift code and using the `find` in it, you should have written so.


Anyway, you have not show enough info, so I need to guess, but you might want to do something like this:

    func rowCheck(_ value: Int) -> (location:String, pattern: String)? {
        let acceptableFinds = ["011","110","101"]
        let findFuncs = [checkTop, checkBottom, checkLeft, checkRight, checkMiddleAcross, checkMiddleDown, checkDiagLeftRight, checkDiagRightLeft]
        for algorthm in findFuncs {
            let algorthmResults = algorthm(value)
            if acceptableFinds.contains(algorthmResults.pattern) { //<- use `contains(_:)` of Array
                return algorthmResults
            }
        }
        return nil
    }


If this is not what you want, you may need to describe what you really want to do more precisely.

Depends on many things.


  • In what class do you write your `rowCheck(_:)` method?
  • In what class does your `find(_:_:)` is defined?
  • What are `checkTop, checkBottom, checkLeft, ...`


All such things affects. Please show enough info.


And one more, please use code insertion feature of this site. Jus click the icon `<>`.

import UIKit

class ViewController: UIViewController {

@IBOutlet var ticTacImg1: UIImageView!

@IBOutlet var ticTacImg2: UIImageView!

@IBOutlet var ticTacImg3: UIImageView!

@IBOutlet var ticTacImg4: UIImageView!

@IBOutlet var ticTacImg5: UIImageView!

@IBOutlet var ticTacImg6: UIImageView!

@IBOutlet var ticTacImg7: UIImageView!

@IBOutlet var ticTacImg8: UIImageView!

@IBOutlet var ticTacImg9: UIImageView!

@IBOutlet var ticTacBtn1: UIButton!

@IBOutlet var ticTacBtn2: UIButton!

@IBOutlet var ticTacBtn3: UIButton!

@IBOutlet var ticTacBtn4: UIButton!

@IBOutlet var ticTacBtn5: UIButton!

@IBOutlet var ticTacBtn6: UIButton!

@IBOutlet var ticTacBtn7: UIButton!

@IBOutlet var ticTacBtn8: UIButton!

@IBOutlet var ticTacBtn9: UIButton!

@IBOutlet var resetBtn: UIButton!

@IBOutlet var userMessage: UILabel!

var plays = Dictionary<Int,Int>()

var done = false

var aiDeciding = false

@IBAction func UIButtonClicked(sender: UIButton){

userMessage.isHidden = true

if !(plays[sender.tag] != nil) && !aiDeciding && !done{

setImageForSpot(spot: sender.tag, player: 1)

}

checkForWin()

/

}

func setImageForSpot(spot:Int, player:Int) {

let playerMark = player == 1 ? "x" : "o"

plays[spot] = player

switch spot {

case 1:

ticTacImg1.image = UIImage(named: playerMark)

case 2:

ticTacImg2.image = UIImage(named: playerMark)

case 3:

ticTacImg3.image = UIImage(named: playerMark)

case 4:

ticTacImg4.image = UIImage(named: playerMark)

case 5:

ticTacImg5.image = UIImage(named: playerMark)

case 6:

ticTacImg6.image = UIImage(named: playerMark)

case 7:

ticTacImg7.image = UIImage(named: playerMark)

case 8:

ticTacImg8.image = UIImage(named: playerMark)

case 9:

ticTacImg9.image = UIImage(named: playerMark)

default:

ticTacImg5.image = UIImage(named: playerMark)

}

}

@IBAction func resetBtnClicked(sender:UIButton){

done = false

resetBtn.isHidden = true

userMessage.isHidden = true

reset()

}

func reset(){

plays = [:]

ticTacImg1.image = nil

ticTacImg2.image = nil

ticTacImg3.image = nil

ticTacImg4.image = nil

ticTacImg5.image = nil

ticTacImg6.image = nil

ticTacImg7.image = nil

ticTacImg8.image = nil

ticTacImg9.image = nil

}

func checkForWin(){

let whoWon = ["I":0,"You":1]

for (key,value) in whoWon {

if plays[7] == value && plays[8] == value && plays[9] == value || /

plays[4] == value && plays[5] == value && plays[6] == value || /

plays[1] == value && plays[2] == value && plays[3] == value || /

plays[7] == value && plays[4] == value && plays[1] == value || /

plays[8] == value && plays[5] == value && plays[2] == value || /

plays[9] == value && plays[6] == value && plays[3] == value || /

plays[9] == value && plays[5] == value && plays[1] == value || /

plays[7] == value && plays[5] == value && plays[3] == value

{

userMessage.isHidden = false

userMessage.text = "Looks like \(key) won!"

resetBtn.isHidden = false

done = true

}

}

}

func checkBottom(_ value: Int) -> (location: String, pattern: String){

return ("bottom", checkFor(value: value, inList: [7,8,9]))

}

func checkMiddleAcross(_ value: Int) -> (location: String, pattern: String){

return ("bottom", checkFor(value: value, inList: [4,5,6]))

}

func checkTop(_ value: Int) -> (location: String, pattern: String){

return ("bottom", checkFor(value: value, inList: [1,2,3]))

}

func checkLeft(_ value: Int) -> (location: String, pattern: String){

return ("bottom", checkFor(value: value, inList: [1,4,7]))

}

func checkMiddleDown(_ value: Int) -> (location: String, pattern: String){

return ("bottom", checkFor(value: value, inList: [2,5,8]))

}

func checkRight(_ value: Int) -> (location: String, pattern: String){

return ("bottom", checkFor(value: value, inList: [3,6,9]))

}

func checkDiagLeftRight(_ value: Int) -> (location: String, pattern: String){

return ("bottom", checkFor(value: value, inList: [1,5,9]))

}

func checkDiagRightLeft(_ value: Int) -> (location: String, pattern: String){

return ("bottom", checkFor(value: value, inList: [3,5,7]))

}

func checkFor(value: Int, inList: [Int]) -> String {

var conclusion = ""

for cell in inList {

if plays[cell] == value {

conclusion += "1"

} else {

conclusion += "0"

}

}

return conclusion

}

func rowCheck(_ value: Int) -> (location:String, pattern: String)? {

var acceptableFinds = ["011","110","101"]

var findFuncs = [checkTop, checkBottom, checkLeft, checkRight, checkMiddleAcross, checkMiddleDown, checkDiagLeftRight, checkDiagRightLeft]

for algorthm in findFuncs{

var algorthmResults = algorthm(value)

if find(acceptableFinds,algorthmResults.pattern){

return algorthmResults

}

}

}

func aiTurn(){

if done{

return

}

aiDeciding = true

/

if let result = rowCheck(0) {

}

aiDeciding = false

}

override func viewDidLoad() {

super.viewDidLoad()

/

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

/

}

}

Accepted Answer

Do you really want to solve your issue? You have ignored some of my askings:

In what class does your `find(_:_:)` is defined?

And one more, please use code insertion feature of this site. Jus click the icon `<>`.


If you have found an old Swift code and using the `find` in it, you should have written so.


Anyway, you have not show enough info, so I need to guess, but you might want to do something like this:

    func rowCheck(_ value: Int) -> (location:String, pattern: String)? {
        let acceptableFinds = ["011","110","101"]
        let findFuncs = [checkTop, checkBottom, checkLeft, checkRight, checkMiddleAcross, checkMiddleDown, checkDiagLeftRight, checkDiagRightLeft]
        for algorthm in findFuncs {
            let algorthmResults = algorthm(value)
            if acceptableFinds.contains(algorthmResults.pattern) { //<- use `contains(_:)` of Array
                return algorthmResults
            }
        }
        return nil
    }


If this is not what you want, you may need to describe what you really want to do more precisely.

That's the TICTACTOE game you are copying ; you should tell in your post.


For the problem, may be the signature of find() function is not matching your use.


Check precisely how you have written it (including lower/uppercase)

In addition, does find() return a bool value ? Or some type of optional ?


Please post your code of find() function

Thank you for your response.


You are right. The code I am copying is three years old. I am sure there's been tons of changes to the syntax.


Also, the answer I got from OOper solved my problem. The 'find' method seems to be no longer supported. I re-wrote the function using OOper's code, and it worked like a charm. Thanks OOper.


Full Disclosure:


I am trying to update code from a video posted on YouTube by Skip Wilson on Jun 10, 2014: Swift Programming Tutorial Part 5: Making a Game (Tic Tac Toe with AI)

Jun 10, 2014: Swift Programming Tutorial Part 5: Making a Game (Tic Tac Toe with AI)

Seems too old to learn the current Swift programming. According to the date, the Swift used in the video seems to be a beta version pre-1.0.

Maybe Swift then had a global function `find(_:_:)`.


Swift is changing very fast since it has been first introduced. You should better find an up-to-date tutorial to learn Swift programming, the history of Swift may not be what you want to learn. You may find a Tic-Tac-Toe in modern Swift, if you are good at web-searching.

I always search for the latest version of swift, but It seems that everything I find interesting is unfortunately slightly out of date - I search mainly on YouTube.


For the most part, I am able to update the syntax utilizing the IDE recomendations; however, when the IDE offers no recommendations, I have no choice but to ask for help.


Thanks again for all your help.

Seeing the fact that you could have fixed many other parts of the old code, I wonder if you need video tutorials.


You can find hundreds times more good tutorials if you include text based pages.


Anyway it's your choice. Have a nice programming.

Use of unresolved identifier 'find'
 
 
Q