问题: 我正在寻找的是在表格中显示这些信息,所以我认为我需要:
MyHouses1 [第] [行] .getAddressDetails()
如何正确定义MyHouses1?
import UIKit
class House {
var address = "Address"
var street = "Street"
var city = "City"
var state = "State"
var zip = "Zip"
func getAddressDetails() -> String {
return "\(address) \(street) \(city) \(state) \(zip)"
//return "\(address) \(street)"
}
func getCityState() -> String {
return "\(city) - \(state)"
}
}
class newhouse: House {
var lighting = "crappy"
var plumbing = "sucks"
var heating = "heats good"
var cooling = "cools good"
var repairs = "needs alot of repairs"
func getFixtureDetails() -> String {
return "\(lighting) \(plumbing) \(heating) \(cooling)"
}
}
// THIS WORKS
var MyHouses: [newhouse] = []
MyHouses.append(newhouse())
MyHouses[0].address = "test"
MyHouses[0].getAddressDetails()
// THIS DOESN'T WORK
var MyHouses1: [[newhouse]] = [] // No Error Yet
MyHouses1.append // Getting an error here, not sure how to append
详细信息:为了发布网站,我希望我添加更多详细信息.....所以这里我要添加更多详细信息lol
答案 0 :(得分:1)
你可以这样做..
var MyHouses1: [[newhouse]] = []// No Error Yet
var houses = [newhouse]() //Initialize your `newhouse` array here
for i in 0...4 {
houses += [newhouse()]
}
MyHouses1 += [houses]
print("\(MyHouses1[0][0].city)") // will print "City"