如何将两个数组合并为一个结构

问题描述:

我想要我的快速代码执行的操作是将两个数组在视图控制器中初始化,然后将它们移入添加的结构中.我想做传输,因为它确实加载了.我不知道自己在做什么,所以我放了一些我认为可能有用的代码,但是现在我的代码在加载时没有编译.

What I want my swift code to do is take the two arrays initilized in view controller and then move them into the struct added. I want to do the transfer in view did load. I dont know what I am doing so I put some code that I thought might be helpful but right now my code is not compiling in view did load.

import UIKit

class ViewController: UIViewController {
    
    var emptyA = [Int]()
    var emptyb = [UIImage]()
    
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        added.init(emptyA, emptyb)
    }


}
struct added {
    var arrayOne = //emptyA
    var arrayTwo = //emptyb
    
    
}

您需要这样声明您的结构:

You need to declare your struct like this:

struct Added {
    var arrayOne: [Int]
    var arrayTwo: [UIImage]
}

然后声明一个实例,您将执行此操作:

Then to declare an instance you would do this:

let a = Added(arrayOne: emptyA, arrayTwo: emptyb)

此外,通常以将大写字母开头的结构名称作为一种好形式.

Also, it's typically good form to start the name of your structs with a capital letter.