You need to just set it as,
Target = CompiledImage;
No need of *. Since both are pointers basically you are assigning the memory address and not copying the contents if you use the above code.
On a side note, please start variable names with lowercase letters. Target normally represents a class name. As per apple coding conventions, it should be target.
As per your comment, you can do the following,
In ViewController class, declare a UIImage as @property,
@property (nonatomic, retain) UIImage *downloadedImage;
While doing URL call,
NSImageLoader *imageLoader = [[NSImageLoader alloc] init];
[imageLoader setTarget:self];//setting current viewController as target instead of UIImage
When image is downloaded,
-(void) connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"Finished Downloading Image: %@" ,[connection.originalRequest.URL absoluteString]);
UIImage *CompiledImage=[UIImage imageWithData:ImageData];
SEL selector=@selector(ImageDownloadingCompleted:Image:);
if([[self Delegate] respondsToSelector:selector]){
[[self Delegate] ImageDownloadingCompleted:self Image:CompiledImage];
}
else{
if(Target){
Target.downloadedImage = CompiledImage;//or [Target setDownloadedImage:CompiledImage];
}
}
// NSLog(@"Image Size:%i", [ImageData length]);
}
In your ViewController class, now you can access image as, self.downloadedImage which will have same as in CompiledImage with same memory address pointing to the same location.
An alternative way is to declare UIImage *Target as UIImage **Target in your NSImageLoader class. And while calling setTarget method, use [imageLoader setTarget:&Target];. Inside this method you need to set target as Target = Target;
Update:
Based on your comments it should be like this,
for( NSDictionary *CurrentActivity in [Profile UserActivities]) {
...
UIImage *WineImage = [UIImage imageNamed:@"loader.gif"];
NSImageLoader *loader=[[NSImageLoader alloc] initWithURLString:[NSString stringWithFormat:@"%@%@",[TempSettings URL],[CurrentActivity objectForKey:@"ImageURL"]]];
[loader setTarget:&WineImage];
[loader startDownloading];
[self addSubview:Activity];
Counter++;
}
Then in NSImageLoader.h file @interface,
__strong UIImage **Target; //This should be strong not autoreleasing
In NSImageLoader.m file,
- (void)setTarget:(UIImage *__strong *)iTarget{ //change here also
Target = target;
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"Finished Downloading Image: %@" ,[connection.originalRequest.URL absoluteString]);
UIImage *CompiledImage=[UIImage imageWithData:ImageData];
SEL selector=@selector(ImageDownloadingCompleted:Image:);
if([[self Delegate] respondsToSelector:selector]){
[[self Delegate] ImageDownloadingCompleted:self Image:CompiledImage];
}
else{
if(Target){
*Target = CompiledImage;
}
}
// NSLog(@"Image Size:%i", [ImageData length]);
}
Update2:
Using the approach of passing UIImageView, you can do the following,
for( NSDictionary *CurrentActivity in [Profile UserActivities]) {
...
UIImage *WineImage = [UIImage imageNamed:@"loader.gif"];
NSImageLoader *loader=[[NSImageLoader alloc] initWithURLString:[NSString stringWithFormat:@"%@%@",[TempSettings URL],[CurrentActivity objectForKey:@"ImageURL"]]];
[loader setTarget:Activity];//pass imageview and let the delegate method set image
[loader startDownloading];
[self addSubview:Activity];
Counter++;
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"Finished Downloading Image: %@" ,[connection.originalRequest.URL absoluteString]);
UIImage *CompiledImage=[UIImage imageWithData:ImageData];
SEL selector=@selector(ImageDownloadingCompleted:Image:);
if([[self Delegate] respondsToSelector:selector]){
[[self Delegate] ImageDownloadingCompleted:self Image:CompiledImage];
}
else{
if(Target){
Target.image = CompiledImage;
}
}
// NSLog(@"Image Size:%i", [ImageData length]);
}
Here pass imageview and let the delegate method set image in that once you have downloaded the image.