[ios] How to load specific image from assets with Swift

I'm new to Swift and I want to load a special image from assets. For example I have:

image 1 for iphone 4s = [email protected]
image 2 for iphone 5/5s = [email protected]
image 3 for iphone 6s = [email protected]

and I want to load for iphone 6 a specific image like

self.GSquare = SKSpriteNode(imageNamed: "./Images.xcassets/[email protected]")

Is it possible?

This question is related to ios image swift size assets

The answer is


You can easily pick image from asset without UIImage(named: "green-square-Retina").

Instead use the image object directly from bundle.
Start typing the image name and you will get suggestions with actual image from bundle. It is advisable practice and less prone to error.

See this Stackoverflow answer for reference.


Since swift 3.0 there is more convenient way: #imageLiterals here is text example. And below animated example from here:

enter image description here


Examples related to ios

Adding a UISegmentedControl to UITableView Crop image to specified size and picture location Undefined Symbols error when integrating Apptentive iOS SDK via Cocoapods Keep placeholder text in UITextField on input in IOS Accessing AppDelegate from framework? Autoresize View When SubViews are Added Warp \ bend effect on a UIView? Speech input for visually impaired users without the need to tap the screen make UITableViewCell selectable only while editing Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

Examples related to image

Reading images in python Numpy Resize/Rescale Image Convert np.array of type float64 to type uint8 scaling values Extract a page from a pdf as a jpeg How do I stretch an image to fit the whole background (100% height x 100% width) in Flutter? Angular 4 img src is not found How to make a movie out of images in python Load local images in React.js How to install "ifconfig" command in my ubuntu docker image? How do I display local image in markdown?

Examples related to swift

Make a VStack fill the width of the screen in SwiftUI Xcode 10.2.1 Command PhaseScriptExecution failed with a nonzero exit code Command CompileSwift failed with a nonzero exit code in Xcode 10 Convert Json string to Json object in Swift 4 iOS Swift - Get the Current Local Time and Date Timestamp Xcode 9 Swift Language Version (SWIFT_VERSION) How do I use Safe Area Layout programmatically? How can I use String substring in Swift 4? 'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator Safe Area of Xcode 9 The use of Swift 3 @objc inference in Swift 4 mode is deprecated?

Examples related to size

PySpark 2.0 The size or shape of a DataFrame How to set label size in Bootstrap How to create a DataFrame of random integers with Pandas? How to split large text file in windows? How can I get the size of an std::vector as an int? How to load specific image from assets with Swift How to find integer array size in java Fit website background image to screen size How to set text size in a button in html How to change font size in html?

Examples related to assets

FlutterError: Unable to load asset How to load specific image from assets with Swift Laravel assets url Adding external resources (CSS/JavaScript/images etc) in JSP How to pass a file path which is in assets folder to File(String path)? Using fonts with Rails asset pipeline How to get the android Path string to a file on Assets folder? How to get URI from an asset File? How to copy files from 'assets' folder to sdcard? Play audio file from the assets directory