簡體   English   中英

使用未解決的標識符?

[英]Use of unresolved identifier?

我在四個不同的位置Use of unresolved identifier "Rule"
var ruleslet rule1let rule2let rule3
我究竟做錯了什么?

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

如果Rule在框架中定義,則必須將其標記為public才能使用。
如果在同一模塊中定義,則必須將其標記為internal (Swift會隱式地)或public

我認為, Rule是在同一模塊中定義的。 因此,它可能有助於重啟Xcode。
沒有更多信息,很難說出問題出在哪里。

更新:

因此,我假設您的項目看起來像這樣:

項目

Rule.swift (或項目中的任何文件)中,您必須已定義Rule類型。 例如,它可能看起來像這樣:

規則快速

如果尚未定義Rule類型,則可能需要先閱讀《 Swift編程語言手冊》 ,然后再繼續。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM