2014-10-01 5 views
5

यहां मेरा कोड है, किसी भी मदद की बहुत सराहना की है धन्यवाद! यह स्विफ्ट में एक्सकोड में लिखा गया था। मैं त्रुटि है कि कहा गया है बार आ रही है "एक लाइन पर लगातार घोषणाओं द्वारा अलग किया जाना चाहिए ';' 'मैं स्विफ्ट में यह त्रुटि प्राप्त कर रहा हूं। "एक लाइन पर अभिसरण घोषणा अलग होनी चाहिए ';'

 import UIKit 

class View Controller: UIViewController { 
@IBOutlet var outputLabel: UILabel! = UILabel() 

var currentCount : Int = 0 

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. 
} 


@IBAction func addOneButton(sender: UIButton) { 

    currentCount = currentCount + 1 
    if(currentCount <= 1) { 
     outputLabel.text = "The button has been clicked 1 time!" 
    outputLabel.textColor = UIColor.purpleColor() 
    } 
    else { 
    outputLabel.text = "The button has been clicked \(currentCount) number of times." 
    outputLabel.textColor = UIColor.redColor() 


     var Hello: UILabel! { 
      if(currentCount >= 5) { 
       outputLabel.text = "Don't Forget To Give A GOOD Rating! :D" 
      outputLabel.textColor = UIColor.orangeColor() 
      } 
      else { 
       outputLabel.text = "Nothing To See Here..." 
       } 
+0

कौन सा लाइन आप त्रुटि मिलता है? –

उत्तर

4

ऐसा लगता है कि कक्षा के नाम में दृश्य और नियंत्रक के बीच आपके पास अतिरिक्त स्थान था और बहुत सारे गुम बंद होने वाले कोष्ठक भी थे।

इस प्रयास करें:

import UIKit 

class ViewController: UIViewController { 
    @IBOutlet var outputLabel: UILabel! = UILabel() 

    var currentCount : Int = 0 

    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. 
    } 


    @IBAction func addOneButton(sender: UIButton) { 

     currentCount = currentCount + 1 
     if(currentCount <= 1) { 
      outputLabel.text = "The button has been clicked 1 time!" 
      outputLabel.textColor = UIColor.purpleColor() 
     } 
     else { 
      outputLabel.text = "The button has been clicked \(currentCount) number of times." 
      outputLabel.textColor = UIColor.redColor() 

      var Hello: UILabel! { 
       if(currentCount >= 5) { 
        outputLabel.text = "Don't Forget To Give A GOOD Rating! :D" 
        outputLabel.textColor = UIColor.orangeColor() 
       } 
       else { 
        outputLabel.text = "Nothing To See Here..." 
       } 
       return outputLabel 
      } 
     } 
    } 
} 
+0

असल में यह काम नहीं किया, चौथी से आखिरी पंक्ति में एक त्रुटि मिली। –

+0

खुशी है कि आपने इसे हल किया है। कृपया उन उत्तरों को स्वीकार करना सुनिश्चित करें जो आपके लिए उपयोगी हैं। यह वास्तव में सराहना की है। –

+0

क्या आप मेरी मदद कर सकते हैं, फिर भी चौथी से आखिरी पंक्ति में एक त्रुटि है जो कहती है "UILabel लौटने की उम्मीद में एक समारोह में वापसी!" –

0
var Hello: UILabel! { 

इस लाइन गलत लग रहा है। इसे हटा दो।

संपादित

वहाँ भी } अंत में गायब है।
सही ढंग से आपके कोड को इंडेंट करने से ऐसी त्रुटियों को बहुत मदद मिलेगी!

संपादित 2

ओह और मुझे लगता है कि तुम्हारा मतलब class ViewController बजाय class View Controller

+0

मैंने उस रेखा को हटाने का प्रयास किया, इसने और त्रुटियां बनाईं। साथ ही, पाठ के साथ एक लेबल की पहचान है, इसलिए मैंने यह नहीं लिखा कि लाइन एक्सकोड आपके लिए यह करता है। जवाब के लिए धन्यवाद। –

+0

'var Hello: UILabel का उद्देश्य क्या है! { '? कोड इस समय कोई समझ नहीं आता है। मुझे आश्चर्य है कि एक्सकोड भी इसे संकलित करता है। – fluidsonic

+0

जब मैंने एक नया लेबल जोड़ा, तो मैंने विकल्प को निष्पादक को इसके लिए कोड लिखने के लिए खींच लिया, जो मुझे विश्वास है कि यह आपको करना है। –

संबंधित मुद्दे

 संबंधित मुद्दे