任何人都可以帮助我们解决这些Xcode错误吗?

时间:2017-06-08 04:53:58

标签: ios swift xcode

我正在尝试为我的教会制作应用并正在观看一系列YT教程,但我收到了很多错误:enter image description here

import UIKit
import Firebase

class ViewController: UIViewController {
  @IBOutlet weak var emailField: UITextField!
  @IBOutlet weak var passwordField: UITextField!
  @IBOutlet weak var myWebView: UIWebView!

  @IBAction func Website(sender AnyObject) {

    if let url = NSURL(string: :"http://www.sermonaudio.com/source_detail.asp?sourceid=cfbc1")
    UIApplication.sharedApplication().openURL(url) {
    }

    var userUid: String!

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

      getVideo(videoCode: "qS6tvqL1N24")
    }

    override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
    }

    func goToCreateUserVC(){
      performSegue(withIdentifier: "Feed", sender: nil)
    }
    func goToFeedVC() {
      performSegue(withIdentifier: "Feed", sender: nil)
    }
    func getVideo(videoCode:String!)
    {
      let url = URL(string: "https://www.youtube.com/embed/\(videoCode)")
      myWebView.loadRequest(URLRequest(url: url!))
    }
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if segue.identifier == "SignUp" {
        if let destination = segue.destination as? UserVC {
          if userUid != nil {
            destination.userUid = userUid
          }
          if emailField.text != nil {
            destination.emailField = emailField.text
          }
          if passwordField.text != nil {
            destination.passwordField = passwordField.text
          }
        }
      }
    }

    @IBAction func signInTapped(_ sender: Any){
      if let email = emailField.text, let password = passwordField.text {
        FIRAuth.auth()?.signIn(withEmail: email, password: password, completion:
          { (user,error) in
            if error == nil {
              if let user = user {
                self.userUid = user.uid
                self.goSignUpVC()
              }
            } else {
              self.goToCreateUserVC()
            }
        });
      }
    }
  }

}

1 个答案:

答案 0 :(得分:1)

欢迎来到SO :)请在下次问题中发布您的代码,您也可以嵌入您的图片文件,以帮助我们更轻松地查看您的问题。

您忘记添加":" Website(sender: AnyObject)

在下一行,你把你的" {"一行下来太远了。它需要在if语句的末尾,而不是在UIApplication.sharedApplication....

之后

还有其他一些标点错误。

当您看到错误说"覆盖只能在课程中使用"这通常意味着你在某个地方忘记了一个右大括号(你做了)。您可以选择整个程序,然后执行"编辑器 - >结构 - >重新缩进"这将帮助您查看范围问题的位置(这是我修复覆盖问题的方法)。

请务必阅读并注意您的错误消息。其中一个明确告诉您,您错过了" {"在你的if语句之后,当你看到"期望的表达式"这意味着无论你写的是对Swift的胡言乱语(意味着你最有可能输入错字,或留下不完整的东西)。

我继续为您编辑了您的问题,并修复了您的代码。我没有使用几乎没有任何你正在使用的东西(我编程游戏),但我只是按照Xcode给我的指示(中心有点的那些告诉你如何修复它) ):

class ViewController: UIViewController {
  @IBOutlet weak var emailField: UITextField!
  @IBOutlet weak var passwordField: UITextField!
  @IBOutlet weak var myWebView: UIWebView!

  @IBAction func Website(sender: AnyObject) {

    if let url = URL(string: "http://www.sermonaudio.com/source_detail.asp?sourceid=cfbc1") {
      UIApplication.shared.openURL(url)
    }
  }
  var userUid: String!

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

    getVideo(videoCode: "qS6tvqL1N24")
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }

  func goToCreateUserVC(){
    performSegue(withIdentifier: "Feed", sender: nil)
  }
  func goToFeedVC() {
    performSegue(withIdentifier: "Feed", sender: nil)
  }
  func getVideo(videoCode:String!)
  {
    let url = URL(string: "https://www.youtube.com/embed/\(videoCode)")
    myWebView.loadRequest(URLRequest(url: url!))
  }
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "SignUp" {
      if let destination = segue.destination as? UserVC {
        if userUid != nil {
          destination.userUid = userUid
        }
        if emailField.text != nil {
          destination.emailField = emailField.text
        }
        if passwordField.text != nil {
          destination.passwordField = passwordField.text
        }
      }
    }
  }

  @IBAction func signInTapped(_ sender: Any){
    if let email = emailField.text, let password = passwordField.text {
      FIRAuth.auth()?.signIn(withEmail: email, password: password, completion:
        { (user,error) in
          if error == nil {
            if let user = user {
              self.userUid = user.uid
              self.goSignUpVC()
            }
          } else {
            self.goToCreateUserVC()
          }
      });
    }
  }
}

此外,它看起来像是较旧的Swift代码,因此您会收到错误。尝试寻找用Swift 3编写的教程(或下载旧的Xcode)。

教程很棒,但他们很少教你如何解决问题。那时你必须依赖调试器和Xcode错误。尝试在这里搜索您的错误,如果您仍然在努力,那么您可以随时发布一个问题:P

祝你的应用好运!