Foo is a container View...I wanted to hide the Holder inside Foo but was getting this compile error. So I ask this question...why I'm not allow to put nest Holder?
You cannot declare static properties inside generic types. The language doesn't support it today. This is because the semantics aren't very clear, should Structure<Int> share the same static variables as Structure<String> or should they be distinct? You probably should be able to do the former, but that hasn't been decided yet and behaviour and syntax are simply not designed. Hence, the compiler bans it outright.
This applies to nested or top level types, static properties inside generic types simply are not allowed anywhere. In your case, as Foo is generic on content, then any nested type inside Foo is also generic on content (this might be easier to grasp if you think about the fully-qualified type of Holder β it is Foo<content>.Holder).
struct Foo<content: Hashable> {
struct Holder {
static var x: Int { 0 }
}
}
with this, my generic SwiftUI.View can directly implement PreferenceKey. So I can avoid defining free standing PreferenceKey and refer to its Type as Self.self