user6270694
user6270694

Reputation:

Where to store images in iOS project

I'm new to iOS development. I have created a simple iOS app where I have many buttons with images inside. Also cells of UITableView in my application contains images.

Up to now I have put all images for buttons and cells in the "Assets.xcassets" folder. The images can also be accessed if I locate all images in separate directory (let say "Images" folder).

Where is the correct place to locate images? As far as I know in "Assets.xcassets" app logo, tab bar icons can be located, but I don't know is it allowed to store all images in that folder.

Upvotes: 9

Views: 6966

Answers (2)

Papershine
Papershine

Reputation: 5233

You can store any resource you like in the Assets.xcassets folder. Simply drag and drop the images into the Assets.xcassets folder and use them. There is no limit to what type of asset you put in the Assets.xcassets catalog. Of course, you can add a new asset catalog. It can be found in File > New > File, scrolling down to Resource and then clicking Asset Catalog. It acts the same as Assets.xcassets and the usage is the same.

asset catalog

For example, if you put an image called foo in an asset catalog called Bar.xcassets, you can still use

UIImage("foo")

without specifying the name of your catalog.

Upvotes: 7

Avt
Avt

Reputation: 17053

In general you should use assets for all static images you have in an app. Assets were introduced for a better handling of images with different resolutions for different devices (like @2x, @3x for retina devices). When user installs the app not all versions of the same image are downloaded but only that one that fits the best user's device. So your app will take less space which is good. Also assets are more convenient if you have several versions with different resolutions for the same image.

If you want you can place images in several assets. To add a new asset go to File > New > File and choose Asset Catalog in Resource section.

Upvotes: 4

Related Questions