push/append swift 中的数组

push/append an Array in swift

如何将push/append数据放入这个数组var tempArray = [[],[],[]]

我尝试附加此数据

  tempCart[0] = (uuid as? NSArray)!  //string
  tempCart[1] = (fileName as? NSArray)! //string
  tempCart[2] = (imageData as? NSArray)! //NSData

但它显示“从字符串转换为无关类型'NSArray'总是失败”

更新 现在我试了这条线

tempCart += [[uuid],[fileName],[imageData]]

当我将所有字符串放入数组时一切顺利,但是当我放入 'imageData' 时出现此错误 'type of expression is ambiguous without more context'

这里有一些代码变体供您使用:

var tempArray = [(String, String, NSData)]()
let oneElem = (uuid, fileName, imageData)
tempArray.append(oneElem)

...

tempArray[0].0 // you can access to uuid of 1st element
tempArray[8].1 // you can access to fileName of 7th element

试试这个代码使用元组而不是 NSArray()

        var Array = [(String, String, NSData)]()
        let secondArray = (uuid, fileName, imageData)
        Array.append(secondArray)
        print(Array)