type String does not conform to protocol sequencetype

前端 未结 1 1243
说谎
说谎 2020-12-22 08:48

Here is the code, I\'m trying to make a simple calculator :

@IBAction func btnOperatorInput(sender: UIButton) {
    let op = (\"+\", \"-\", \"*\", \"/\")

           


        
相关标签:
1条回答
  • 2020-12-22 09:25

    The error is easily solved, you need to access the String's CharacterView:

    for _ in op.0.characters {
    
           self.calc.add(Int(nr1)!, secondNumber: Int(nr2)!)
    
    }
    

    Note: As another commenter has queried above, I'm not sure why you'd want to iterate over what will always be a single and predictable character but I guess this might just be example code.

    0 讨论(0)
提交回复
热议问题