我知道如何以编程方式执行此操作,但我确信有一种内置方式...
我使用的每种语言都有一些对象集合的默认文本表示,当你尝试将Array与字符串连接起来时,它会吐出来,或者将它传递给print()函数等等.Apple的Swift语言吗?有一种内置的方法可以轻松地将Array转换为String,或者在对数组进行字符串化时我们是否总是要显式?
如何从具有String属性的对象数组创建字符串?
class Person {
let name: String
}
let people = [Person(name: "Sam"), Person(name: "Zoey"), Person(name: "Bil")]
let peopleNames: String = //what should be here?
peopleNames = "Sam, Zoey, Bil"
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个类似它的URL https://api.website.com/products?product_ids=1,2,3,4,5 使用CoreData中的整数数组
到目前为止,我有此代码
let array = [1,2,3,4,5]
var urlComponents = URLComponents()
urlComponents.scheme = "https"
urlComponents.host = "api.website.com"
urlComponents.path = "/products"
urlComponents.queryItems = [
URLQueryItem(name: "product_ids", value: ???????),
]
Run Code Online (Sandbox Code Playgroud)
如何添加数组数据以获得所需的完整URL? https://api.website.com/products?product_ids=1,2,3,4,5