Avatar
norio_nomura 4/24/2018 3:23 AM
dynamicMemberLookup 把握。subscript(dynamicMember:)の実装を必要とするアトリビュートなんだね。 @swift-4.2.4 @dynamicMemberLookup indirect enum UID: CustomStringConvertible { case root(String) case leaf(parent: UID, String) subscript(dynamicMember member: String) -> UID { return .leaf(parent: self, member) } var description: String { switch self { case .root(let string): return string case .leaf(let parant, let string): return "\(parant).\(string)" } } } let root = UID.root("root") print(root.a.b.c)