我正在尝试为我的教堂制作一个应用程序,并且正在观看一堆 YT 教程,但是我遇到了很多错误:
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()
}
});
}
}
}
}
欢迎来到 SO :) 下次请在问题中发布您的代码,您也可以嵌入您的图像文件以帮助我们更轻松地查看您的问题。
您忘记添加“:” Website(sender: AnyObject)
在下一行,您将“{”一行放得太远了。它需要放在 if 语句的末尾,而不是在UIApplication.sharedApplication....
还有一些其他标点符号错误。
When you see an error saying "override can only be used in a class" that typically means you forgot a closing brace somewhere (which you did). You can select the whole program then do "Editor -> Structure -> Re-indent" which will help you to see where the scope issue is (this is how I fixed the override issue).
Make sure to read and pay attention to your error messages.. one of them clearly tells you that you are missing the "{" after your if statement, and when you see "expected expression" that means that whatever you wrote was gibberish to Swift (meaning you had a typo most likely, or left something incomplete).
我继续为您编辑了您的问题,并修复了您的代码。我几乎没有使用过你正在使用的任何东西(我编写游戏),但我只是按照 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
祝你的应用程序好运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句