Structを使用して、Facebookのグラフリクエストから取得した変数(電子メール、名前、性別など)を渡そうとしています。 Struct( 'fbDemographics ')と' ViewController 'の変数を使用していますが、' SecondViewController '(タイプ' ViewController 'に' fbDemographics 'というメンバがありません)の変数と構造体を呼び出そうとするとエラーが発生します。私は構造体を使用したことがないので、なぜこのエラーが出るのか分かりません。どんな考えにも感謝します。両方のビューコントローラのコードは以下の通りです:Structを使用して変数を渡すSwift
class ViewController: UIViewController, FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
struct fbDemographics {
static var relationship_status: String?
static var gender: String?
static var user_education_history: String?
static var user_location: String?
static var email: String?
static var name: String?
}
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, relationship_status, gender, user_location, user_education_history, email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
//let fbDetails = result as! NSDictionary
//print(fbDetails)
if let userDataDict = result as? NSDictionary {
fbDemographics.gender = userDataDict["gender"] as? String
fbDemographics.email = userDataDict["email"] as? String
fbDemographics.name = userDataDict["name"] as? String
fbDemographics.user_location = userDataDict["user_location"] as? String
fbDemographics.user_education_history = userDataDict["user_education_history"] as? String
fbDemographics.relationship_status = userDataDict["relationship_status"] as? String
let myEducation = fbDemographics.user_education_history
let myEmail = fbDemographics.email
let myGender = fbDemographics.gender
let myName = fbDemographics.name
let myStatus = fbDemographics.relationship_status
let myLocation = fbDemographics.user_location
self.performSegue(withIdentifier: "LoginToHome", sender: (Any).self)
}
}
SECONDビューコントローラ
class SecondViewController: UIViewController {
@IBAction func verticalSliderChanged(_ sender: UISlider) {
let currentValue = String(sender.value);
sliderLabel.text = "\(currentValue)"
func viewDidLoad() {
super.viewDidLoad()
***ViewController.fbDemographics.myEmail***
}
}
あなたの現在のソリューションと間違ったことがたくさんあります。ビューコントローラ間でデータを渡す際のチュートリアルを検索します。 – nathan
私は多くのチュートリアルを行ってきました。ただ単に変数を渡すことはありませんが、私は病気が止まっていると思います。見ていただきありがとうございます。 –
質問に不必要なコードがたくさんあります。重要なものだけを削除してください。 – Macabeus