I am trying to convert some code to Objective-C from Java, and I am getting stiff when converting parts of Java Generic. For example, declaring a class in Java, I believe, says that the current class extends any class that is a subclass of the Component class, in Objective-C, does this mean that you are simply extending the Component class?
Any help anyone can provide will be greatly appreciated. Moving forward with this will help me convert other parts of the code that are similar. Thanks
Java:
public class ComponentMapper<T extends Component> { private Class<T> classType; public ComponentMapper(Class<T> type, World world) { this.type = ComponentTypeManager.getTypeFor(type); this.classType = type; } public T get(Entity e) { return classType.cast(em.getComponent(e, type)); } }
Objective-C:
@interface ComponentMapper : Component { ComponentType* componentType; EntityManager* entityManager; id classType; } - (id) init:(id) componentType World:(World*) world; - (id) get:(Entity*) entity; // can this just return Entity instead @end @implementation ComponentMapper - (ComponentMapper*) init:(id) type World:(World *) world { if (self = [super init]) { // should be a call to getEntityManager() self->entityManager = [world entityManager]; self->componentType = [ComponentTypeManager getTypeFor:type]; self->classType = type; } return self; } - (id) get:(Entity*) entity { return [classType cast:[em getComponent:e param1:type]]; } @end
source share