ios - 如何从 swift 3 中的键值对中删除符号?

标签 ios swift3

我有一个如下所示的字典,我需要删除键中的 $ 符号,并需要将与此处所示相同的数据存储在一个单独的数组中,谁能帮我如何从所有键中删除美元?

var products = ["$50-$60": 50-60, "$30-$40": 30-40, "$0-$10": -10, "$20-$30": 20-30, "$90-and above": 90-, "$40-$50": 40-50, "$80-$90": 80-90, "$70-$80": 70-80, "$10-$20": 10-20, "$60-$70": 60-70]

最佳答案

据我所知,我希望你想要数组中的一组键

var dollarRemovedArray = products.map{$0.key.replacingOccurrences(of: "$", with: "")}

输出将是这样的--

["50-60", "30-40", "0-10", "20-30", "90-and above", "40-50", "80-90", "70-80", "10-20", "60-70"]

关于ios - 如何从 swift 3 中的键值对中删除符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46462677/

相关文章:

ios - 如何在 SWIFT 中设置 CGPDFOperatorTableSetCallback(不是 Objective C)

iOS : 3. 4 : App names in iTunes Connect and as displayed on a device should be similar, 以免造成混淆

ios - 如果从另一个 View Controller 调用,则 Collection View 中的单元格不可见

sprite-kit - 无法转换 'SKScene' 类型的值

ios - 错误 ITMS-90096 : "Your binary is not optimized for iPhone 5"

ios - 使用 XCTestCase 将项目插入到 Collection View 失败

ios - reachabilityWithHostName 不起作用

ios - 为什么我保存在目录中的图像在安装新版本后不显示?

swift - Swift3 函数声明中新的 "for"、 "at"、 "in"关键字是什么?

ios - 如何将 json 解码为键中有空格的结构/类对象?