String Array to String转换Swift

时间:2016-09-28 21:17:39

标签: ios swift nsuserdefaults alamofire

我在someKey键下的nsuserdefaults中存储了一个字符串数组。

我正在构建Alamofire查询:

var params = [
        "long": lon,
        "lat": lat,
        "startDate": DateCalc.convertValueToDate(defaults.floatForKey("startDate"))
    ] as [String: AnyObject]

Alamofire.request(.GET, "\(serverURL)/tests", parameters: (params))
        .validate()
        .responseJSON { response in

现在,基于某些条件,我想在我的params数组中追加先前设置的String数组。

我尝试这样做:

params["someKey"] = defaults.objectForKey("someKey")

然后输入参数如下:

params: ["long": 19.09421499999999, "someKey": <__NSCFArray 0x7f8322713990>(

一个, 二, 三 ) ,“lat”:51.90671500000001,“startDate”:2011-09-28T00:00:00.000Z]

我该如何更改它以便我可以传递字符串数组,例如:

params: ["long": 19.09421499999999, "someKey": "one, two three", "lat": 51.90671500000001,"startDate": 2011-09-28T00:00:00.000Z]

1 个答案:

答案 0 :(得分:3)

let joinedString = ["one", "two", "three", "four", "five"].joinWithSeparator(", ")

print(joinedString)