Swift-删除硬编码字符串的最佳方法是什么?

问题描述 投票:0回答:2

字典键显示为硬编码字符串,因此搜索了删除它的最佳方法。

let sentObj : [String:Any] = [
    "id": Int(objData["_id"] as! String)!,
    "boolPresentValue": "234",
    "compositePropertiesString":objData["compositePropertiesString"]!
]
ios swift string dictionary
2个回答
2
投票

我们使用的方法是创建一个私有结构,保留所有字符串文字并使用它。

类似

private struct ViewControllerCosntants {
    static let category = "Category"
    static let rating = "Rating"
    static let currentNav = "Current Nav"
    static let type = "Type"
}

并像]一样使用它>

ViewControllerCosntants.category

我需要的地方。


0
投票
dict.removeValue(forKey: willRemoveKey)
© www.soinside.com 2019 - 2024. All rights reserved.