预期声明Erro Ios Excode

时间:2016-12-12 20:24:11

标签: swift xcode compiler-errors

在我的代码中,我不断收到预期的声明错误。通常它会告诉您我的代码中问题的确切位置。出于某种原因,它直接位于底部。我查看了我的代码,一切看起来还不错。

这是我的代码

import UIKit
class Draft: UIViewController {

    @IBOutlet weak var confirmDraft: UILabel!

    @IBOutlet weak var turn: UILabel!


    @IBOutlet weak var playerInQuestion: UILabel!
    @IBOutlet weak var choice: UITextField!

    var Tone = [ ""]
    var Ttwo = [ ""]
    var Tthree = [ ""]
    var Tfour = [ ""]


    var pn=["Albert Pujols"," Miguel Cabrera "," Lou Gehrig"," Roberto Alomar"," Joe Morgan"," Jackie Robinson"," Ozzie Smith"," Cal Ripken jr"," Omar Vizquel"," Adrian Beltre"
        ,"Brooks Robinson ","Wade Boggs "," Johnny Bench","Carlton Fisk "," Joe Maurer","Ty Cobb "," Mike Trout"
        ," Tim Raines"," Ken Griffey Jr","Ted Williams "
        ," Pete Rose","Hank Aaron ","Roberto Clemente "," Tony Gwynn"," Frank Thomas"," Edgar Martinez"," David Ortiz","Tom Seaver "," nolan Ryan "," Walter johnson"]

    var oneDo =  false
    var twoDo = false
    var threeDo = false
    var fourDo = false


    var Toneturn  = true
    var Ttwoturn = false
    var Tthreeturn = false
    var Tfourturn  = false
    var currentPos: Int = 0

    var j = 0
    var k = 0
    var count = 0

    var onePos = 0
    var twoPos = 0
    var threePos = 0
    var fourPos = 0

    var turns = [""]
    var scount = ""
    var oc = 0
    var tc = 0
    var thc = 0
    var f = 0
    var piq = ""

    @IBOutlet weak var mybutton: UIButton!
    @IBOutlet weak var pickTwo: UIButton!
    @IBOutlet weak var pickThree: UIButton!
    @IBOutlet weak var pickFour: UIButton!


    @IBAction func draft (sender: AnyObject)
    {

        // piq = shownextPlayer()
        if(Tone.count < 11)
        {
            if !Tone.contains(choice.text!) && !Ttwo.contains(choice.text!) && !Tthree.contains(choice.text!) && !Tfour.contains(choice.text!)
            {
                Tone.append(choice.text!)
                //pn.removeAtIndex(pn.indexOf(choice.text!)!)
                confirmDraft.text = "Player Drafted To Team One"
                if pn.count >= 20
                {
                    mybutton.enabled = false
                    pickTwo.enabled = true
                    turn.text = "Team Two's Turn"
                }

            }
            else
            {
                confirmDraft.text = "Player is already added to a team"
            }
        }
        else
        {
            confirmDraft.text = "Team Roster is Full"
        }
        print("Team One has \(Tone.count)")
        var j = 0

        while j < Tone.count
        {
            print(Tone[j])
            j = j + 1
        }

        pickFour.enabled = false
        pickThree.enabled = false
    }

    @IBAction func TeamTwo (sender: AnyObject)
    {

        // piq = shownextPlayer()
        // if !pn.contains(choice.text!)
        //// {
        //     return
        //   }
        if mybutton.enabled == true{
            confirmDraft.text = "Team One Must Go First"
            return
        }
        if(Ttwo.count < 11)
        {
            if !Tone.contains(choice.text!) && !Ttwo.contains(choice.text!) && !Tthree.contains(choice.text!) && !Tfour.contains(choice.text!)
            {
                Ttwo.append(choice.text!)
                //pn.removeAtIndex(pn.indexOf(choice.text!)!)
                confirmDraft.text = "Player Drafted To Team Two"
                if pn.count >= 30
                {
                    pickThree.enabled = true
                    pickTwo.enabled = false
                    turn.text = "Team's Three Turn"
                }
                else
                {
                    mybutton.enabled = true
                    pickTwo.enabled = false
                    turn.text = "Team One's Turn"
                }
            }
            else
            {
                confirmDraft.text = "Player is already added to a team"
            }
        }
        else
        {
            confirmDraft.text = "Team Roster is Full"
        }
        print("Team Two Count \(Ttwo.count)")

        var j = 0

        while j < Ttwo.count
        {
            print(Ttwo[j])
            j = j + 1
        }
    }

    @IBAction func TeamThree (sender: AnyObject)
    {

        // piq = shownextPlayer()

        //if !pn.contains(choice.text!)
        // {
        //   return

        // }

        if mybutton.enabled == true{
            confirmDraft.text = "Team One Must Go First"
            return
        }


        var i = 0

        while i < pn.count
        {
            if pn[i] == choice.text!
            {
                return
            }
            i = i + 1
        }

        if(Tthree.count < 11)
        {


            if !Tone.contains(choice.text!) && !Ttwo.contains(choice.text!) && !Tthree.contains(choice.text!) && !Tfour.contains(choice.text!)
            {
                Tthree.append(choice.text!)
                //pn.removeAtIndex(pn.indexOf(choice.text!)!)
                confirmDraft.text = "Player Drafted To Team Three"
                if pn.count >= 40
                {
                    pickFour.enabled = true
                    pickThree.enabled = false
                    turn.text = "Team Four's Turn"
                }
                else{
                    mybutton.enabled = true
                    pickThree.enabled = false
                    turn.text = "Team One's Turn"
                }



            }
            else
            {

                confirmDraft.text = "Player is already added to a team"
            }


        }
        else
        {
            confirmDraft.text = "Team Roster is Full"
        }
        print("Team Three has \(Tthree.count)")

        var j = 0

        while j < Tthree.count
        {
            print(Tthree[j])
            j = j + 1
        }
    }

    @IBAction func TeamFour (sender: AnyObject)
    {

        // piq = shownextPlayer()
        // if !pn.contains(choice.text!)
        //  {
        // //      return
        //  }
        if mybutton.enabled == true{
            confirmDraft.text = "Team One Must Go First"
            return
        }
        if(Tfour.count < 11)
        {
            if !Tone.contains(choice.text!) && !Ttwo.contains(choice.text!) && !Tthree.contains(choice.text!) && !Tfour.contains(choice.text!)
            {
                Tfour.append(choice.text!)
                //pn.removeAtIndex(pn.indexOf(choice.text!)!)
                confirmDraft.text = "Player Drafted To Team Four"
                pickFour.enabled = false
                turn.text = "Team One's Turn"
                mybutton.enabled = true
            }
            else
            {

                confirmDraft.text = "Player is already added to a team"
            }
        }
        else
        {
            confirmDraft.text = "Team Roster is Full"
        }
        print("Team Four has \(Tfour.count)")
    }

    @IBAction func showNextPlayer (sender: AnyObject)
    {

        if currentPos == pn.count
        {
            currentPos = 0
        }
        let nameString: String = pn[currentPos]
        playerInQuestion.text = nameString
        currentPos = currentPos + 1
    }
}

1 个答案:

答案 0 :(得分:0)

.isEnabled

替换所有UIButtons对象 .enable 属性

详细

Xcode 8.1,Swift 3

固定代码

import UIKit
class Draft: UIViewController {

    @IBOutlet weak var confirmDraft: UILabel!
    @IBOutlet weak var turn: UILabel!
    @IBOutlet weak var playerInQuestion: UILabel!
    @IBOutlet weak var choice: UITextField!

    var Tone = [ ""]
    var Ttwo = [ ""]
    var Tthree = [ ""]
    var Tfour = [ ""]

    var pn=["Albert Pujols"," Miguel Cabrera "," Lou Gehrig"," Roberto Alomar"," Joe Morgan"," Jackie Robinson"," Ozzie Smith"," Cal Ripken jr"," Omar Vizquel"," Adrian Beltre"
        ,"Brooks Robinson ","Wade Boggs "," Johnny Bench","Carlton Fisk "," Joe Maurer","Ty Cobb "," Mike Trout"
        ," Tim Raines"," Ken Griffey Jr","Ted Williams "
        ," Pete Rose","Hank Aaron ","Roberto Clemente "," Tony Gwynn"," Frank Thomas"," Edgar Martinez"," David Ortiz","Tom Seaver "," nolan Ryan "," Walter johnson"]

    var oneDo =  false
    var twoDo = false
    var threeDo = false
    var fourDo = false

    var Toneturn  = true
    var Ttwoturn = false
    var Tthreeturn = false
    var Tfourturn  = false
    var currentPos: Int = 0

    var j = 0
    var k = 0
    var count = 0

    var onePos = 0
    var twoPos = 0
    var threePos = 0
    var fourPos = 0

    var turns = [""]
    var scount = ""
    var oc = 0
    var tc = 0
    var thc = 0
    var f = 0
    var piq = ""

    @IBOutlet weak var mybutton: UIButton!
    @IBOutlet weak var pickTwo: UIButton!
    @IBOutlet weak var pickThree: UIButton!
    @IBOutlet weak var pickFour: UIButton!

    @IBAction func draft (sender: AnyObject)
    {
        // piq = shownextPlayer()
        if(Tone.count < 11)
        {
            if !Tone.contains(choice.text!) && !Ttwo.contains(choice.text!) && !Tthree.contains(choice.text!) && !Tfour.contains(choice.text!)
            {
                Tone.append(choice.text!)
                //pn.removeAtIndex(pn.indexOf(choice.text!)!)
                confirmDraft.text = "Player Drafted To Team One"
                if pn.count >= 20
                {
                    mybutton.isEnabled = false
                    pickTwo.isEnabled = true
                    turn.text = "Team Two's Turn"
                }

            }
            else
            {
                confirmDraft.text = "Player is already added to a team"
            }
        }
        else
        {
            confirmDraft.text = "Team Roster is Full"
        }
        print("Team One has \(Tone.count)")
        var j = 0

        while j < Tone.count
        {
            print(Tone[j])
            j = j + 1
        }

        pickFour.isEnabled = false
        pickThree.isEnabled = false
    }

    @IBAction func TeamTwo (sender: AnyObject)
    {

        // piq = shownextPlayer()
        // if !pn.contains(choice.text!)
        //// {
        //     return
        //   }
        if mybutton.isEnabled == true {
            confirmDraft.text = "Team One Must Go First"
            return
        }
        if(Ttwo.count < 11)
        {
            if !Tone.contains(choice.text!) && !Ttwo.contains(choice.text!) && !Tthree.contains(choice.text!) && !Tfour.contains(choice.text!)
            {
                Ttwo.append(choice.text!)
                //pn.removeAtIndex(pn.indexOf(choice.text!)!)
                confirmDraft.text = "Player Drafted To Team Two"
                if pn.count >= 30
                {
                    pickThree.isEnabled = true
                    pickTwo.isEnabled = false
                    turn.text = "Team's Three Turn"
                }
                else
                {
                    mybutton.isEnabled = true
                    pickTwo.isEnabled = false
                    turn.text = "Team One's Turn"
                }
            }
            else
            {
                confirmDraft.text = "Player is already added to a team"
            }
        }
        else
        {
            confirmDraft.text = "Team Roster is Full"
        }
        print("Team Two Count \(Ttwo.count)")

        var j = 0

        while j < Ttwo.count
        {
            print(Ttwo[j])
            j = j + 1
        }
    }

    @IBAction func TeamThree (sender: AnyObject)
    {

        // piq = shownextPlayer()

        //if !pn.contains(choice.text!)
        // {
        //   return

        // }

        if mybutton.isEnabled == true{
            confirmDraft.text = "Team One Must Go First"
            return
        }

        var i = 0

        while i < pn.count
        {
            if pn[i] == choice.text!
            {
                return
            }
            i = i + 1
        }

        if(Tthree.count < 11)
        {
            if !Tone.contains(choice.text!) && !Ttwo.contains(choice.text!) && !Tthree.contains(choice.text!) && !Tfour.contains(choice.text!)
            {
                Tthree.append(choice.text!)
                //pn.removeAtIndex(pn.indexOf(choice.text!)!)
                confirmDraft.text = "Player Drafted To Team Three"
                if pn.count >= 40
                {
                    pickFour.isEnabled = true
                    pickThree.isEnabled = false
                    turn.text = "Team Four's Turn"
                }
                else{
                    mybutton.isEnabled = true
                    pickThree.isEnabled = false
                    turn.text = "Team One's Turn"
                }
            }
            else
            {

                confirmDraft.text = "Player is already added to a team"
            }
        }
        else
        {
            confirmDraft.text = "Team Roster is Full"
        }
        print("Team Three has \(Tthree.count)")

        var j = 0

        while j < Tthree.count
        {
            print(Tthree[j])
            j = j + 1
        }
    }

    @IBAction func TeamFour (sender: AnyObject)
    {

        // piq = shownextPlayer()
        // if !pn.contains(choice.text!)
        //  {
        // //      return
        //  }
        if mybutton.isEnabled == true{
            confirmDraft.text = "Team One Must Go First"
            return
        }
        if(Tfour.count < 11)
        {
            if !Tone.contains(choice.text!) && !Ttwo.contains(choice.text!) && !Tthree.contains(choice.text!) && !Tfour.contains(choice.text!)
            {
                Tfour.append(choice.text!)
                //pn.removeAtIndex(pn.indexOf(choice.text!)!)
                confirmDraft.text = "Player Drafted To Team Four"
                pickFour.isEnabled = false
                turn.text = "Team One's Turn"
                mybutton.isEnabled = true
            }
            else
            {
                confirmDraft.text = "Player is already added to a team"
            }
        }
        else
        {
            confirmDraft.text = "Team Roster is Full"
        }
        print("Team Four has \(Tfour.count)")
    }

    @IBAction func showNextPlayer (sender: AnyObject)
    {

        if currentPos == pn.count
        {
            currentPos = 0
        }
        let nameString: String = pn[currentPos]
        playerInQuestion.text = nameString
        currentPos = currentPos + 1
    }
}