2014-06-09 5 views
-4

내 코드가 끝나면 3 타격을하면 아웃이 하나씩 올라갑니다. 하단 if 문에 오류가 나타납니다. 그것은 예상 선언을 말합니다스위프트 Xcode 6 개발자 야구 카운터

// 
// ViewController.swift 
// helloWordDemo 
// 
// Created by Developer on 6/8/14. 
// Copyright (c) 2014 AECApps. All rights reserved. 
// 

import UIKit 

class ViewController: UIViewController { 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 
@IBOutlet var labelDispaly : UILabel = nil 
// dispaly Strikes 

var counter = 1 

@IBAction func buttonPressed(sender : AnyObject) { 

    labelDispaly.text = "Strikes \(counter++)" 
} 
//button to add strikes 

@IBOutlet var OutsDispaly : UILabel = nil 

var outsCounter = 1 
//outs dispaly 

@IBAction func outsButtonPressed(sender : AnyObject) { 

    OutsDispaly.text = "Outs \(outsCounter++)" 

} 
//button to add outs 
if counter = 3 { 
    outsCounter ++ 
    } 
} 
+0

'if' 문을 사용하는 코드가 어떤 함수에도 포함되어 있지 않습니다. – Jack

답변

1

문제는 if 문이 함수 안에 없다는 것입니다. 명령문이 class 외부에있을 때도 문제가 없지만이 경우는 아닙니다. 명령문을 실행하는 함수를 작성하십시오. 수업이 추가 : 또한

func updateOuts(){ 
    if counter == 3 { 
     outsCounter++ 
    } 
} 

, 당신은 == 대신 = 사용해야 내부 문합니다. 이는 ==이 두 값을 비교하고 =이 변수를 설정하기 때문입니다.

+0

lol 어떻게 그렇게할까요? – AECapuano

+0

이 함수를 클래스에 추가하고 'outsCounter'를 업데이트해야 할 때마다 호출하십시오. – 68cherries

+0

omg 나는 바보 같은 느낌이 든다. 완성 된 코드를 게시 할 수는있다. – AECapuano