我试图从this answer实现解决方案,但是我只是无法使其工作。我得到“未解决的标识符的使用......”因为我试图访问的变量..Swift:从不同的swift文件中访问其他类的变量
我有一个loginViewController.swift当有人登录在获取用户名和密码..
import UIKit
类loginViewController:UIViewController的{
@IBOutlet weak var userEmailTextField: UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func loginButtonTapped(sender: AnyObject) {
let userEmail = userEmailTextField.text;
let userPassword = userPasswordTextField.text;
然后,我有一个PostService.swift文件从MySQL数据库中获取数据。应该使用的人登录后才能访问相关数据的用户名..
import Foundation
类PostService {
var settings:Settings!
let userEmail = "[email protected]"; //This is hard coded but needs to come from the loginViewController
let userPassword = "1234"; //This is hard coded but needs to come from the loginViewController
我已尝试和一些其他的建议,我似乎只是没有能够得到它的工作..请帮助..
谢谢提前。
你能分享你正在使用的实际代码吗?你如何实例化PostService类?您需要全局声明变量,您可以使用self关键字来访问它们。 –