Addressing and pointers in object C
So here's the problem.
I have a method (or a message that is called in obj-C) I am passing a pointer to an object.
inside this method, I'm going to change what this pointer is pointing to and release the old object. And I would like the instance variable (which is passed to the method) to reference the new value assigned to it. basically having a variable, works like an OUT parameter in languages ββlike C #
-(NSDictionary *) GetListWithCommand:(NSString*) command andCache:(CachedMutableDictionary*) cache
{
CachedMutableDictionary* Dictionary = [Getfrom somesource];
CachedMutableDictionary* temp = cache;
cache = [Dictionary retain];
[temp release];
}
so I believe I need to send the referenced address for the cache variable and then be able to reference it at both the address level and the object level.
it might also be smarter / simpler to create a copy method in the CachedMutableDictionary class.
a source to share
Yes, it looks like this method needs to take the CachedMutableDictionary ** that the caller and the cache are accessing. The last three lines of the method:
CachedMutableDictionary *temp = *cache;
*cache = [Dictionary retain];
[temp release];
It smells funny to me. Where does the cache start from? Is it always an instance variable of an object? Why not just walk through the facility?
a source to share
You just need to add some stars here and there:
-(NSDictionary *) GetListWithCommand:(NSString*) command
andCache:(CachedMutableDictionary**) cache
{
CachedMutableDictionary* Dictionary = [Getfrom somesource];
CachedMutableDictionary* temp = *cache;
*cache = [Dictionary retain];
[temp release];
}
a source to share