Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.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 如何在swift中将[AnyObject]数组转换为字符串_Ios_Swift - Fatal编程技术网

Ios 如何在swift中将[AnyObject]数组转换为字符串

Ios 如何在swift中将[AnyObject]数组转换为字符串,ios,swift,Ios,Swift,例如:类似于[“A12”,1,2,“Test”]的数组。 我的预期结果应该能够绑定到textfield中,或者使用组件分隔符(,)获取字符串 let array: [Any] = ["A12", 1, 2, "Test"] let tmpArray = array.map({ return String(describing: $0)}) let string = tmpArray.joined(separator: ",") print(string) 你可以

例如:类似于[“A12”,1,2,“Test”]的数组。
我的预期结果应该能够绑定到textfield中,或者使用组件分隔符(,)获取字符串

    let array: [Any] = ["A12", 1, 2, "Test"]
    let tmpArray = array.map({ return String(describing: $0)})
    let string = tmpArray.joined(separator: ",")
    print(string)

你可以用这个来完成

    let array: [Any] = ["A12", 1, 2, "Test"]
    let tmpArray = array.map({ return String(describing: $0)})
    let string = tmpArray.joined(separator: ",")
    print(string)

首先将值映射到
String
值,然后使用您喜欢的分隔符将它们连接起来:

let description: String = ["A12", 1, 2, "Test"].map{ String(describing: $0) }.joined(separator: ", ")
print(description)

首先将值映射到
String
值,然后使用您喜欢的分隔符将它们连接起来:

let description: String = ["A12", 1, 2, "Test"].map{ String(describing: $0) }.joined(separator: ", ")
print(description)

是否仅从数组中获取字符串?请尝试使用
joinWithSeparator(“,”)
它应返回类似“A12,1,2,Test”的字符串。不清楚预期的输出是什么:字符串数组还是字符串。你能在问题中澄清这一点吗?也许可以举一个例子说明您的输出应该是什么样子的?您想只从数组中获取字符串吗?尝试使用
joinWithSeparator(“,”)
它应该返回一个类似“A12,1,2,Test”的字符串。不清楚预期的输出是什么:字符串数组还是字符串。你能在问题中澄清这一点吗?也许可以举一个例子,说明您的输出应该是什么样子的?