簡體   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