Lincoln Eckhardt
Lincoln Eckhardt

Reputation: 13

Swift: Use of instance member on type 'ViewController'; did you mean to use a value of type 'ViewController' instead

As the title suggests, Swift is telling me I'm calling a member on the ViewController class, not an object. I've looked at numerous other posts and cannot figure out where I'm going wrong.

func endEventSteps() {
    UserDefaults.standard.set(false, forKey: "hasLoggedIn")
    UserDefaults.standard.set(nil, forKey: "usersEmail")
    UserDefaults.standard.set(nil, forKey: "usersPassword"
    performSegue(withIdentifier: "backToLoginScreen", sender: self)
}
let alertController = UIAlertController(title: "End event", message: "Are you sure you'd like to end this event?", preferredStyle: UIAlertControllerStyle.alert)
let DestructiveAction = UIAlertAction(title: "End",
                                          style: UIAlertActionStyle.destructive,
                                          handler: {(alert: UIAlertAction!) in endEventSteps()})

EDIT: I get the following error on the last line: "Use of instance member 'endEventSteps' on type 'InfoSubmisionViewController'; did you mean to use a value of type 'InfoSubmisionViewController' instead?". code compiles fine when I put simple command as the handler, such as print("foo")

All of the above code is within a custom ViewController class, 'InfoSubmissionViewController'.

Upvotes: 1

Views: 1259

Answers (1)

Russell
Russell

Reputation: 5554

Assuming that you have a controller class named DestructiveAction, then

let DestructiveAction = ...

should be

let destructiveAction = ...

Upvotes: 2

Related Questions