Old chestnut, sort of partially solved but still problems.
Now we can nest types in generic types, what I want is :
class Event<typeT>
{
class Args
{
public static let empty = Args() // error : Static stored properties not supported in generic types
}
}
But the static let is not directly in the generic class.
It's still generic, though, because of the outer generic class, so there is a different static var for each specialization. For example, the following assert would fail:
This IMHO isn't a bug as the behavior is not completely defined. Joanna mentioned that Args is not generic, but it actually is, once you address it from global namespace - as it inherits the T type (while not used anywhere):
Which is the root of the problem - you are currently not actually using the same class under different event types. It then makes a static property an issue as you are not able to distinguish these two scenarios with current language:
- is the stored property the same for all variations of the Args class?
- or does each type has its own stored property?
I can think of cases for both. And this is (from what I understood is the core of the problem).
@Joanna - in this particular case, I don't see the benefit of Args.empty over Args() as you currently create a new instance all the time. If the arguments are not intended to be generic, much better solution is to do something like:
class EventArgs {
public static let empty = Args()
}
public class EventArgs
{
public static let empty = EventArgs()
}
public class PropertyChangedEvent : Event<Any, PropertyChangedEvent.Args>
{
public class Args : EventArgs
{
public static let allProperties = PropertyChangedEvent.Args()
public let propertyName: String?
public init(_ propertyName: String? = nil)
{
self.propertyName = propertyName
}
}
}