草庐IT

AnyKeyPath

全部标签

swift - 如何将 AnyKeyPath 转换为 WritableKeyPath?

我有一个枚举案例数组,其中每个案例都有一个keyPath属性,它返回一个AnyKeyPath匹配与枚举案例同名的类属性:protocolPathAccessor:CodingKey{varkeyPath:AnyKeyPath{get}staticvarallCases:[Self]{get}init?(rawValue:Int)}extensionPathAccessor{staticvarallCases:[Self]{varcases:[Self]=[]varindex:Int=0whileletelement=Self.init(rawValue:index){cases.app