objective c - How to populate a stack with objects of various types -


Using an NSMutableArray ivar, I plan to write a class that acts like a stack and should be capable of enabling different types of objects.

Every time he threatens to get out of the stack objects, because almost all have been recovered so far, they automatically get some objects-generic-possible "object emitter" for example, There should be official classes that return examples of NSImages or NSString or any other conceivable type, which should be placed on the stack, but each has to be treated separately in different ways.

What is the easiest way for those object-emitting classes to "plug in" my stack class? The stack class should not need to be aware of the type of object with which it needs to be settled, this is where some "helper classes" can set it - but I have no indication of when their location will be. I tried dynamic creation using NSClassFromString, but it does not look right at all.

NSMutableArray is capable of storing an object unlike generic collection in Java, where the data structure is divided into specific sections Examples preserve, cocoa allows you to add anything to an NSArray. Therefore, your pop method can easily remove the last object of the array, to see if the size is smaller than some thresholds, and then request new objects from the supplier class.

For example: - (NSObject *) Pop {NSObject * poppedObject = [mutableArray lastObject]; [MutableArray removeLlastObject]; If ([mutantArray count] & lt; SMALLEST_ALLOWABLE_STACK_SIZE} {{[MYContentProvider * provider in contentProviders]) {{mutableArray addObjectsFromArray: [fetchContent of the provider]]; }} Returned the popup object; }

Comments