Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference b/w imageNamed and imageWithContentsOfFile [closed]

What is the difference b/w imageNamed and imageWithContentsOfFile in ObjectiveC

like image 877
Graham Bell Avatar asked Nov 30 '22 01:11

Graham Bell


2 Answers

imageNamed: imageNamed cache’s your images and you lose control over the memory - there's no guarantee that releasing the object will actually release the image but does provide faster loading of images second time around as they are cached. If you are using Interface Builder, and setting the image in Image View Attributes, that is also equal to imageNamed method. The image will be cached immediately when the app is ran

imageWithContentsOfFile : imageWithContentsOfFile does not cache images and is more memory friendly however as it does not cache images and they are loaded much slower. imageWithContentsOfFile: requires you to put the full path. I don't see why imageNamed: wouldn't be recommended, besides the fact that you can't access files outside of the application bundle.

like image 64
Alex Avatar answered Dec 09 '22 16:12

Alex


Got a nice link which explains the difference b/w these two methods image named-vs-image with contents of file

like image 29
Graham Bell Avatar answered Dec 09 '22 15:12

Graham Bell