Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么我可以将结构放在游乐场上的数组中,而不能放在视图控制器中_Ios_Xcode_Swift - Fatal编程技术网

Ios 为什么我可以将结构放在游乐场上的数组中,而不能放在视图控制器中

Ios 为什么我可以将结构放在游乐场上的数组中,而不能放在视图控制器中,ios,xcode,swift,Ios,Xcode,Swift,为什么这在游乐场上可以正常工作,但当我将其放入viewController时,它会返回“viewController.type没有名为extent的成员” 这让我发疯,所以我真的很感激任何帮助 class ViewController: UIViewController { struct TopicBook { var name: String var species: [String] var subject: String

为什么这在游乐场上可以正常工作,但当我将其放入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
    }
        }
试试这个

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

嗨,首先我错过了最后一行的方括号,这是非常重要的!其次,我不认为这有什么帮助,错误信息消失了,但我不能在任何情况下使用sete,只要出现“未解决的标识符”?你说“这在操场上很好工作,并且会产生此错误”。所以我给了你一段代码,它在不改变代码任何部分的情况下消除了错误。您的“在操场上工作”版本不包括方括号。所以你是否能在任何地方使用它并不在这个问题的范围之内@AlexMcGeeyep,这完全是我的错,我在这里写的时候漏掉了方括号。包含方括号的代码在操场上有效,但在视图控制器中无效。你知道我如何让代码工作吗,包括方括号?或者我应该问一个新问题吗?我是这个论坛的新手,不知道它是如何工作的:/“UnresolvedIdentifier”错误意味着“sete”被定义为本地的,您试图从它的范围之外使用它@AlexMcGeehi,首先我错过了最后一行中的方括号,这非常重要!其次,我不认为这有什么帮助,错误信息消失了,但我不能在任何情况下使用sete,只要出现“未解决的标识符”?你说“这在操场上很好工作,并且会产生此错误”。所以我给了你一段代码,它在不改变代码任何部分的情况下消除了错误。您的“在操场上工作”版本不包括方括号。所以你是否能在任何地方使用它并不在这个问题的范围之内@AlexMcGeeyep,这完全是我的错,我在这里写的时候漏掉了方括号。包含方括号的代码在操场上有效,但在视图控制器中无效。你知道我如何让代码工作吗,包括方括号?或者我应该问一个新问题吗?我是这个论坛的新手,不知道它是如何工作的:/“UnresolvedIdentifier”错误意味着“sete”被定义为本地的,您试图从它的范围之外使用它@亚历克斯麦基