简体   繁体   中英

Use of unresolved identifier?

I am getting Use of unresolved identifier "Rule" in four different spots.
At var rules , let rule1 , let rule2 and let rule3 .
What am I doing wrong?

class RulesTableViewController: UITableViewController {

    var rules = [Rule]()
    let cellIdentifier = "TableViewCell"

    override func viewDidLoad() {
        super.viewDidLoad()

        loadRulesData()
    }

    func loadRulesData() {
        let photo1 = UIImage(named: "card1")!
        let rule1 = Rule(name: "Waterfall", photo: photo1, description: "Every player begins drinking, starting with the player who drew the card and continuing in the direction of play. No one can stop drinking until the player before them does.")!

        let photo2 = UIImage(named: "card2")!
        let rule2 = Rule(name: "You", photo: photo2, description: "Player picks someone to drink.")!

        let photo3 = UIImage(named: "card3")!
        let rule3 = Rule(name: "Me", photo: photo3, description: "Player drinks.")!

        rules += [rule1, rule2, rule3] 
    }
}

If Rule is defined in a framework, it must be marked as public for you to use it.
If it is defined in the same module, it has to be marked as internal (which Swift does implicitly) or public .

I would assume, that Rule is defined in the same module. Therefore it might help to restart Xcode.
Without further information, it's hard to say what the problem is though.

Update:

So, I assume your project looks something like this:

项目

In Rule.swift (or whichever file in the project) you must have defined the type Rule . For example it could look like this:

规则快速

If you have not defined the type Rule , you may want to read the Swift Programming Language Book , before continuing.

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