如何在swift的主数组中添加子数组

时间:2016-07-11 05:23:06

标签: ios arrays swift

package main

import (
    "fmt"
    "sync"
    "time"
)

var mu sync.Mutex
var mu1 sync.Mutex
var wg sync.WaitGroup

// var anotherBalance int

func code1() {
    mu.Lock()
    defer mu.Unlock()
    fmt.Println("Entering code1")
    time.Sleep(1 * time.Second)
    fmt.Println("Exiting code1")
}

func code2() {
    mu1.Lock()
    defer mu1.Unlock()
    fmt.Println("Entering code2")
    time.Sleep(1 * time.Second)
    fmt.Println("Exiting code2")
}

func main() {
    wg.Add(1)
    go func() {
        code1()
        wg.Done()
    }()
    wg.Add(1)
    go func() {
        code2()
        wg.Done()
    }()
    wg.Wait()
}

无论如何如何在主阵列中添加照片数组?我已完成以下操作

{
    "firstName": "AA",
    "lastName": "BB,
    "shortName": "CC",
    "nric": "12/AAA(N)123456",
    "gender": "F",
    "dob": "1.1.2000",
    "password": "admin123",
    "photo": {
        "image": "hello",
        "thumb": "world"
    }
}

但输出很糟糕。请让我怎么做。

3 个答案:

答案 0 :(得分:2)

而不是让参数let使其成为var并执行以下操作。您需要指定字典类型,如下所示

let photoArray : [String : AnyObject] = [
            "pic" : "myPhoto"
        ]
var param : [String : AnyObject] = [
            "name" : "UserName"
        ]

param["photo"] = photoArray

答案 1 :(得分:1)

    let photoArray = [[
        "image": "a",
        "thumb": "b"],[
            "image": "a",
            "thumb": "b"]
    ]
let param = [
"firstName": txtFirstName.text as! AnyObject,
"lastName": txtLastName.text as! AnyObject,
"shortName": txtShortName.text as! AnyObject,
"nric":"",
"gender": genderCode,
"dob":txtDOB.text as! AnyObject,
"photo": photoArray

希望你想这样。

答案 2 :(得分:1)

let photoArray:[String:UIImage] = [
    "image": UIImage.init(named: "a.png")!,
    "thumb": UIImage.init(named: "b.png")!
]

let param:[String:AnyObject] = [
    "firstName": "AA",
    "lastName": "BB",
    "shortName": "CC",
    "nric": "",
    "gender": 0,
    "dob": "DD",
    "photo": photoArray
]

你可以这样做