Patricia
Patricia

Reputation: 87

Swift 4 Function parameter var

I am very new to Swift. I am trying to create func...

func circlesDisabledCondition(playerScoreValue: var) {

    if playerScoreValue < 1 {
        circle1.isEnabled = false
    }
    if playerScoreValue < 5 {
        circle5.isEnabled = false
    }
    if playerScoreValue < 50 {
        circle50.isEnabled = false
    }
    if playerScoreValue < 100 {
        circle100.isEnabled = false
    }
    else {
        circlesEnabled()
    }
}

Of course (playerScoreValue: var) doesn't work, I have no idea how can I write it down.

Calling func example (wrong it is just example that I am looking for something like that...)

 circlesDisabledCondition(playerScoreValue: player2ScoreValue)

I am looking for this output.

if player2ScoreValue < 1 {
        circle1.isEnabled = false
    }
    if player2ScoreValue < 5 {
        circle5.isEnabled = false
    }
    if player2ScoreValue < 50 {
        circle50.isEnabled = false
    }
    if player2ScoreValue < 100 {
        circle100.isEnabled = false
    }
    else {
        circlesEnabled()
    }

Many thanks

Upvotes: 0

Views: 145

Answers (1)

Adi219
Adi219

Reputation: 4814

Replace var with whatever type your playerScoreValue is. If it's an integer, use Int, if it's a float, use float etc.

You can call your function with any variable or value as long as it's of the specified type.

Upvotes: 1

Related Questions