为什么在操场上这样做很好,但当我将其放入viewController时,它返回“viewController.type没有名为extent的成员”
这让我很生气,所以我非常感谢你的帮助!!!
class ViewController: UIViewController {
struct TopicBook {
var name: String
var species: [String]
var subject: String
var rotation: [String]
var unit: String
var extra: String
var content: String
var level: [(Int,Int)]
init(name: String, species: [String], subject: String, rotation: [String], unit: String, extra: String, content: String, level: [(Int,Int)]) {
self.name = name
self.species = species
self.subject = subject
self.rotation = rotation
self.unit = unit
self.extra = extra
self.content = content
self.level = level
}
}
var extext = TopicBook (name: "Name" , species: ["species","species"], subject: "subject", rotation: ["rotation"], unit: "unit", extra: "extra", content: "content", level: [(1,1)])
let sete = [extent]
最佳答案
试试这个
struct TopicBook {
var name: String
var species: [String]
var subject: String
var rotation: [String]
var unit: String
var extra: String
var content: String
var level: [(Int,Int)]
init(name: String, species: [String], subject: String, rotation: [String], unit: String, extra: String, content: String, level: [(Int,Int)]) {
self.name = name
self.species = species
self.subject = subject
self.rotation = rotation
self.unit = unit
self.extra = extra
self.content = content
self.level = level
}
}
class ViewController: UIViewController {
var extent:TopicBook?
var extent2:TopicBook?
override func viewDidLoad() {
super.viewDidLoad()
extent = TopicBook (name: "Name" , species: ["species","species"], subject: "subject", rotation: ["rotation"], unit: "unit", extra: "extra", content: "content", level: [(1,1)])
extent2 = TopicBook (name: "JustToShow" , species: ["JustToShow","JustToShow"], subject: "JustToShow", rotation: ["JustToShow"], unit: "JustToShow", extra: "JustToShow", content: "JustToShow", level: [(2,2)])
}
override func viewDidAppear(animated:Bool){
super.viewDidAppear(true)
//If you want it to have multiple TopicBooks inside, do this
//var seteMutable:[TopicBook] = [ ]
//seteMutable =[extent!]
//seteMutable.append(extent2!)
//let seteTrial = seteMutable
//println(seteTrial[0].name)
//println(seteTrial[1].name)
//else if you want it to have just one TopicBook inside, do this
let sete = [extent!]
// sete is a TopicBook array now
//you can use sete[0]
//Placing it inside viewDidAppear is an example, you can define "sete" in anywhere you will use it.
//viewDidAppear gets called after viewDidLoad, this is why i put it here
}
}
关于ios - 为什么我可以将结构放入操场上的数组中而不放在 View Controller 中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31506730/