I seem to have a pointer problem and I can’t seem o fix it. Could someone help me, please?
-(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]);
}
Target is a private variable of type UIImage (declared: UIImage *Target;)
CompiledImage is a UIImage as well. What I want to do is set the contents of the address of target to be the Contents of CompiledTarget. This results in the following error:
Assigning to ‘UIImage’ from incompatible type ‘UIImage *__strong’
I tried :
memccpy(__bridge Target, &CompiledImage, sizeof(Target),sizeof(Target));
and I get this error:
Expected expression
You need to just set it as,
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.
Targetnormally represents a class name. As per apple coding conventions, it should betarget.As per your comment, you can do the following,
In ViewController class, declare a
UIImageas@property,While doing URL call,
When image is downloaded,
In your ViewController class, now you can access image as,
self.downloadedImagewhich will have same as inCompiledImagewith same memory address pointing to the same location.An alternative way is to declare
UIImage *TargetasUIImage **Targetin yourNSImageLoaderclass. And while callingsetTargetmethod, use[imageLoader setTarget:&Target];. Inside this method you need to set target asTarget = Target;Update:
Based on your comments it should be like this,
Then in NSImageLoader.h file @interface,
In NSImageLoader.m file,
Update2:
Using the approach of passing UIImageView, you can do the following,
Here pass imageview and let the delegate method set image in that once you have downloaded the image.