我可以从NSMutableSet转换为Set no problem,但在执行相反的操作时会遇到问题。
例如,这是有效的:
let nsSet = NSMutableSet(array: ["a", "b"])
let swiftSet = nsSet as! Set<String>但当我尝试时:
let nsSet2 = swiftSet as? NSMutableSetnsSet2最终变成了nil。
发布于 2018-02-28 04:28:48
看起来swift Set需要先转换成NSSet:
let nsSet2 = NSMutableSet(set: set as NSSet)或者速记:
let nsSet2 = NSMutableSet(set: set)或者从NSSet到Swift Set再回到NSSet:
let nsSet = NSMutableSet(array: ["a", "b"])
let set = nsSet as! Set<String>
let nsSet2 = set as NSSet
let nsSet3 = NSMutableSet(set: nsSet2)https://stackoverflow.com/questions/49017356
复制相似问题