C.Kelly
C.Kelly

Reputation: 265

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] 
    }
}

Upvotes: 0

Views: 930

Answers (1)

Marcus Rossel
Marcus Rossel

Reputation: 3258

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:

Project

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

Rule.swift

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

Upvotes: 2

Related Questions