Greetings.
I am creating a framework and making heavy use of generics; something I am well used to after many years of expreience in C#, before coming to Swift when it was first launched.
I am getting an error on the declaration of the CommandSet class, which is proving difficult to resolve :
Type 'CommandSet<subjectT, commandIdentifierT, executionContextT, commandT>' does not conform to protocol 'NotifyCommandChanged'
This is accompanied by two "hints"
Unable to infer associated type 'CommandType' for protocol 'NotifyCommandChanged'
… on the declaration of the CommandType associatedtype in NotifyCommandChanged
Inferred type 'commandT' (by matching requirement 'commandChanged') is invalid: does not inherit from 'Command<Self.SubjectType, Self.IdentifierType, Self.ExecutionContextType>'
… on the commandChanged lazy var in CommandSet
I have been working on this for over a day now and would be very grateful if anyone out there can help me see what I am missing.
public protocol StringEnumType : Hashable, RawRepresentable where Self.RawValue == String { }
public protocol ExecutionContext { }
open class Command<subjectT, identifierT : StringEnumType, executionContextT : ExecutionContext>
{
public var text: String?
public func execute() { }
}
public protocol EventArgs { }
public class Event<senderT, argsT : EventArgs>
{
private let sender: senderT
public init(sender: senderT)
{
self.sender = sender
}
public func invoke(with args: argsT)
{
}
}
public struct CommandChangedEventArgs<identifierT : StringEnumType> : EventArgs
{
public let commandIdentifier: identifierT
public let keyPath: AnyKeyPath
}
public typealias CommandChangedEvent<subjectT,
identifierT : StringEnumType,
executionContextT : ExecutionContext,
commandT : Command<subjectT, identifierT, executionContextT>> = Event<CommandSet<subjectT, identifierT, executionContextT, commandT>, CommandChangedEventArgs<identifierT>>
public protocol NotifyCommandChanged
{
associatedtype SubjectType
associatedtype IdentifierType : StringEnumType
associatedtype ExecutionContextType : ExecutionContext
associatedtype CommandType : Command<SubjectType, IdentifierType, ExecutionContextType>
var commandChanged: CommandChangedEvent<SubjectType, IdentifierType, ExecutionContextType, CommandType> { get set }
}
open class CommandSet<subjectT,
commandIdentifierT : StringEnumType,
executionContextT : ExecutionContext,
commandT : Command<subjectT, commandIdentifierT, executionContextT>> : NotifyCommandChanged
{
private lazy var commands: [commandIdentifierT : commandT] = .init()
public lazy var commandChanged: CommandChangedEvent<subjectT, commandIdentifierT, executionContextT, commandT> = .init(sender: self)
}