繁体   English   中英

Swift:识别变量失败

[英]Swift: identifying variable failing

我有一个名为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.

        }
    }
}
}

只要确保以下所有内容都在一个类中即可(例如您的视图控制器),就可以正常工作。

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

        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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