Swift:识别变量失败

时间:2014-12-31 16:06:10

标签: ios variables swift

我有一个名为patternRoom的IBOutlet,但在我的代码中我收到错误。

@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.

        }
    }
}
}

1 个答案:

答案 0 :(得分:2)

只需确保以下内容都在一个类中(如视图控制器),它应该可以正常工作。

@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.

        }
    }