简体   繁体   English

使用未解决的标识符?

[英]Use of unresolved identifier?

I am getting Use of unresolved identifier "Rule" in four different spots. 我在四个不同的位置Use of unresolved identifier "Rule"
At var rules , let rule1 , let rule2 and let rule3 . var ruleslet rule1let rule2let 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. 如果Rule在框架中定义,则必须将其标记为public才能使用。
If it is defined in the same module, it has to be marked as internal (which Swift does implicitly) or public . 如果在同一模块中定义,则必须将其标记为internal (Swift会隐式地)或public

I would assume, that Rule is defined in the same module. 我认为, Rule是在同一模块中定义的。 Therefore it might help to restart Xcode. 因此,它可能有助于重启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 . Rule.swift (或项目中的任何文件)中,您必须已定义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. 如果尚未定义Rule类型,则可能需要先阅读《 Swift编程语言手册》 ,然后再继续。

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

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