-4

I want to carry the variables CorrectAnswerTotal and QuestionsAskedTotal across to my second view controller (Score View Controller) however I keep getting the error message 'Type 'ScoreViewController' has no member 'data''

Could someone tell me how to resolve this please.

Another issue is I am unable to call on these variables separately in my original view controller since adding them into a structure. I am a beginner at programming so is there a certain way that this should be done?

Thanks in advance.

 struct CarryToNextViewController {

var CorrectAnswerTotal = 0
var QuestionsAskedTotal = 0


}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

let ViewController:ScoreViewController = segue.destinationViewController as! ScoreViewController
ScoreViewController.data = CarryToNextViewController(CorrectAnswerTotal: Int, QuestionsAskedTotal: Int)

}

EDIT

Even when renaming ScoreViewController as viewController I still get the same error message. This is the edited code:

  class viewController: UIViewController {


@IBOutlet var QuestionLabel: UILabel!
@IBOutlet var Buttons: [UIButton]!

var Questions = [Question]()
var QuestionNumber = Int()
var AnswerNumber = Int()

struct CarryToNextViewController {

var CorrectAnswerTotal = 0
var QuestionsAskedTotal = 0


}

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)       {

  let ViewController:ScoreViewController = segue.destinationViewController as!  ScoreViewController
  viewController.data = CarryToNextViewController(CorrectAnswerTotal: 0, QuestionsAskedTotal: 0)

}

2
  • To avoid those errors – you are supposed to refer to ViewController rather than ScoreViewController conform to the naming convention by naming variable names starting with a lowercase letter and class names starting with a capital letter. Commented Sep 13, 2016 at 19:49
  • You are assigning values using class type instead of reference on type. Try ViewController.data = CarryToNextViewController(CorrectAnswerTotal: 0, QuestionsAskedTotal: 0) Commented Sep 13, 2016 at 19:50

2 Answers 2

2

ScoreViewController is a class, not a variable. Try ViewController.data = ... instead, though you should rename it to viewController to reduce confusion.

(In fact, using standard variable/class naming throughout would make the code easier to analyze.)

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for your help, however when I change ScoreViewController to viewController I get the error message 'Use of unresolved identifier 'viewController'.
Did you rename ViewController where you assigned a value to it?
I've done that and the code still doesn't seem to work, I've edited it within my question so it will hopefully be clear where I've gone wrong.
@SausageMachine he didn't rename the class, his first view controller is named viewController
|
1

You can't use viewController.data to access let ViewController:ScoreViewController because they have different variable names(first one is UpperCase second one is LowerCase) they should be the same.

Since your first view controller is called viewController to avoid even more confusion I suggest you replace these two line:

let ViewController:ScoreViewController = segue.destinationViewController as!  ScoreViewController
viewController.data = CarryToNextViewController(CorrectAnswerTotal: 0, QuestionsAskedTotal: 0)

with

let destViewController:ScoreViewController = segue.destinationViewController as!  ScoreViewController
destViewController.data = CarryToNextViewController(CorrectAnswerTotal: 0, QuestionsAskedTotal: 0)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.