Question: I understand that to get images from the asset catalog i can use UIImage(named: "fileName") to do it.

however, what if i am getting DATA from the XCAsset catalog? I can't figure this out.

I have tried, 

```
let url = NSBundle.mainBundle().URLForResource("fileName", withExtension: nil)
let data = NSData(contentsOfURL: url!)

```

But it is nil. I do not know how to get data from the XCAssets catalog. If anyone can help me out (googling hasn't helped) please let me know I will be very thankful!

Update:

Why am I trying to get data from an asset catalog? I dragged an animated gif into the asset catalog. And the asset catalog interprets that as DATA. This is why I am trying to get data out of the asset catalog.

Update:
This is a screen shot of my Assets.xcassets folder looks like.

[![image](https://i.stack.imgur.com/ezf6B.png)](https://i.stack.imgur.com/ezf6B.png)
It has a file called "\_Loading" and on the right it is considered a "Data set".
I'm not sure how to get the data set from the Assets catalog.

Answer: 
I am going to answer my own question.

Since iOS 9, the Asset Catalog allows more than just Images. They allow Data sets. In order to get data from the Asset Catalog, you must use the NSDataAsset class.

Example: Assume you have an Data Asset named "CoolJSON"

```
if let asset = NSDataAsset(name: "CoolJSON") {
    let data = asset.data
    let d = try? NSJSONSerialization.JSONObjectWithData(data, options: [])
}

```

In this example I turned an NSData object into a json.

[NSDataAsset class reference](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/NSDataAsset_Class/index.html)
Load gif image from Assets.xcassets file. That`s same for loading json files.

1. NEW: 【New Data Set】 crate a data set and rename "funny" in Assets.xcassets folder. all right, the gif file is added to Assets.xcassets folder.
[![enter image description here](https://i.stack.imgur.com/9mufr.png)](https://i.stack.imgur.com/9mufr.png)
2. USE:

```
NSDataAsset *asset = [[NSDataAsset alloc] initWithName:@"funny"]; 
self.gifImageView.image = [UIImage sd_animatedGIFWithData:asset.data];                                        

```

	* (UIImage \*)sd\_animatedGIFWithData:(NSData \*)data: is a UIImage+GIF category for loading gif image in SDWebImage.