简体   繁体   中英

Swift: identifying variable failing

I have an IBOutlet called patternRoom but in my code I receive an error.

@IBOutlet private weak var patternRoom: UIImageView!

struct gameBegin {
    var playBegin: Bool {
        didSet {
            if playBegin == true {
                println("\(playBegin)")
                // for goes in (up to 3) (up to 5) (up to 10)

                var swipes = Menu()

                if (swipes.no_of_swipes) == 3 {
                    //blahdeblah
                    for i in 0 ..< 3 {
                        patternRoom.image = UIImage(named: "pattern24.png")
                        //error here 'Game.type does not have a member named patternRoom'
                    }

                }

                if (swipes.no_of_swipes) == 5 {
                    //blahdeblah
                }

                if (swipes.no_of_swipes) == 10 {
                    //blahdeblah
                }


            }
            // display picture 1
            // check user input == picture
            // move ahead or error
            // at end display score e.t.c.

        }
    }
}
}

Just make sure that the following is all in a class (like your view controller) and it should work fine.

@IBOutlet weak var patternRoom: UIImageView!

    var playBegin: Bool {
        didSet {
            if playBegin == true {
                println("\(playBegin)")
                // for goes in (up to 3) (up to 5) (up to 10)

                var swipes = Menu()

                if (swipes.no_of_swipes) == 3 {
                    //blahdeblah
                    for i in 0 ..< 3 {
                        patternRoom.image = UIImage(named: "pattern24.png")
                        //error here 'Game.type does not have a member named patternRoom'
                    }

                }

                if (swipes.no_of_swipes) == 5 {
                    //blahdeblah
                }

                if (swipes.no_of_swipes) == 10 {
                    //blahdeblah
                }


            }
            // display picture 1
            // check user input == picture
            // move ahead or error
            // at end display score e.t.c.

        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM