xcode - UIImage using contentsOfFile -


i using

self.imageview.image = uiimage(named: "foo.png")

to select , load images in uiimageview. have images in app under images.xcassets. problem particular init caches image reuse per official apple documentation:

if have image file displayed once , wish ensure not added system’s cache, should instead create image using imagewithcontentsoffile:. keep single-use image out of system image cache, potentially improving memory use characteristics of app.

my view allows cycling through images before selecting one, , memory footprint goes on increasing cycle through , never goes down when navigate view.

so trying use uiimage(contentsoffile: "path file") not cache image. here having trouble programatically getting path of images have stored under images.xcassets.

i have tried using:

nsbundle.mainbundle().resourcepath
,
nsbundle.mainbundle().pathforresource("foo", oftype: "png")

without luck. first 1 resourcepath, on accessing through terminal not see image assets under it, , second 1 nil when use it. there easy way to this?

also looked @ several questions (like this, this , this) no luck. have put images somewhere else able use pathforresource()? right way go this?

it hard imagine no 1 has encountered scenario before :) !

if need use pathforresource() avoiding image caching, not possible work images.xcassets. in case need create group in xcode, , add image there (be sure, image copied copy bundle resources). afterwards write:

var bundlepath = nsbundle.mainbundle().pathforresource("imagename", oftype: "jpg")  var image = uiimage(contentsoffile: bundlepath!)  

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -