【发布时间】:2015-03-25 15:04:41
【问题描述】:
这是我的自定义类...不确定我是否遗漏了任何内容...
import UIKit
class baseMakeUp {
var Image = UIImage()
var Brand: String
var Color: String
var Rating: Int = 0
init (Brand: String, Color: String) {
self.Brand = Brand
self.Color = Color
}
}
我正在尝试在这里实例化...
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let cellIdentifier = "cellIdentifier"
var foundation: [[baseMakeUp]]
var blush: [[baseMakeUp]]
var eyes: [[baseMakeUp]]
var lips: [[baseMakeUp]]
var nails: [[baseMakeUp]]
// put some test data in makeup arrays here...
foundation[0].Brand = "Revlon" -------------> "Expected declaration" error.
foundation[0].Color = "Red"
foundation[0].Rating = 3
foundation[1].Brand = "MAC"
foundation[1].Color = "Blue"
foundation[1].Rating = 4
我没有包含 ViewController 类的其余部分,因为我认为没有必要。
当我尝试为foundation[0].Brand赋值时出现错误
提前感谢您的帮助!
【问题讨论】:
-
感谢大家的帮助。澄清一下,我并没有尝试使用 2D 数组,所以我已经解决了这个问题。然而,即使我创建了一个 BaseMakeUp 类型的新对象,当我尝试附加它时,我仍然会收到“预期声明”错误。我相信错误确实与我的数组声明有关,因为当我再次尝试键入基础时,Xcode 不会像往常一样自动完成或更改单词颜色。不确定缺少什么。
标签: ios arrays class swift instantiation