Guest User

Untitled

a guest
May 20th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. protocol EntityCreator: class {
  2. func createEntity<EntityType: EntityClass & EntityCreatorInitializable>(type: EntityType.Type, _ initialize: @escaping (EntityType) -> Void)
  3. }
  4.  
  5. protocol EntityCreatorInitializable {
  6. init(entityCreator: EntityCreator)
  7. }
  8.  
  9. class EntityClass: NSObject { }
  10.  
  11. class MyClass: EntityClass, EntityCreatorInitializable {
  12. required init(entityCreator: EntityCreator) {
  13. super.init()
  14. // use the entityCreator
  15. }
  16. }
  17.  
  18. // On the entity creator implementation :
  19.  
  20. class EntityCreatorImplementation: EntityCreator {
  21. func createEntity<EntityType: EntityClass & EntityCreatorInitializable>(type: EntityType.Type, _ initialize: @escaping (EntityType) -> Void) {
  22. // This creation doesn't work...
  23. let newEntity = EntityType(entityCreator: self)
  24. initialize(newEntity)
  25. self.toAdd.insert(newEntity)
  26. }
  27. }
Add Comment
Please, Sign In to add comment