我在四个不同的地方得到Use of unresolved identifier "Rule"
在var rules
,let rule1
,let rule2
和let 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]
}
}
答案 0 :(得分:2)
如果在框架中定义Rule
,则必须将其标记为public
才能使用它。
如果它在同一模块中定义,则必须将其标记为internal
(Swift隐式执行)或public
。
我认为,Rule
在同一模块中定义。因此,重启Xcode可能会有所帮助
如果没有进一步的信息,很难说出问题所在。
所以,我认为你的项目看起来像这样:
在Rule.swift
(或项目中的任何文件)中,您必须已定义类型Rule
。例如,它可能如下所示:
如果您尚未定义类型Rule
,则可能需要先阅读Swift Programming Language Book,然后再继续。