Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protocol EntityCreator: class {
- func createEntity<EntityType: EntityClass & EntityCreatorInitializable>(type: EntityType.Type, _ initialize: @escaping (EntityType) -> Void)
- }
- protocol EntityCreatorInitializable {
- init(entityCreator: EntityCreator)
- }
- class EntityClass: NSObject { }
- class MyClass: EntityClass, EntityCreatorInitializable {
- required init(entityCreator: EntityCreator) {
- super.init()
- // use the entityCreator
- }
- }
- // On the entity creator implementation :
- class EntityCreatorImplementation: EntityCreator {
- func createEntity<EntityType: EntityClass & EntityCreatorInitializable>(type: EntityType.Type, _ initialize: @escaping (EntityType) -> Void) {
- // This creation doesn't work...
- let newEntity = EntityType(entityCreator: self)
- initialize(newEntity)
- self.toAdd.insert(newEntity)
- }
- }
Add Comment
Please, Sign In to add comment