swift NSArray转String[]

swift初学者,swift读取配置文件时遇到此问题。根据网上解释尝试均报错,自己尝试解决了,共享出来,有好办法的也请留言哦。谢谢

let swiftStringArr: String[] = ["1", "2"]
let nsArray: NSArray = swiftStringArr
let objArray: AnyObject[] = nsArray as Array //as Array会转换为AnyObject数组
let strArray: String[] = objArray as String[]

 可直接写为 as Array as String[],例子分开写为了说明as Array后转换为的格式

相关推荐