Search code examples
swiftxcodevariablesaugmented-realityviewcontroller

Value of type 'View Controller' has no member?


I am currently making an ar app using swift and Xcode. I was trying to set up a variable to check if a button was already being pressed. I have created the variable in the format I have seen other people recommend when answering similar questions but I keep getting the same 'Value of type 'ViewController' has no member 'isActionPlaying' error.

var isActionPlaying: Bool = false                         -        attempted variable format to declare member

var tankAnchor: TinyToyTank._TinyToyTank?



class ViewController: UIViewController {
    
    @IBOutlet var arView: ARView!
    
    
    @IBAction func tankRightPressed(_ sender: Any) {
        if self.isActionPlaying { return }                -         errors occur on this line
        else { self.isActionPlaying = true }              -         and this line

        tankAnchor!.notifications.tankRight.post()

    }

When trying to find answers to similar questions to help my own situation I saw many people suggesting a format similar to 'var isActionPlaying: String = "" ', but I believe I have followed this format and am still getting the same error.


Solution

  • ... I saw many people suggesting a format similar to 'var isActionPlaying: String = "" ', but I believe I have followed this format and am still getting the same error.

    You need to put the declaration of isActionPlaying inside the class definition. As you've shown it, it precedes the class definition, so it's just a global variable. Do this:

    class ViewController: UIViewController {
        
        @IBOutlet var arView: ARView!
    
        var isActionPlaying: Bool = false
    //...