Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haifengkao/podasset
Unable to find cocoapods resources? Here is the solution!
https://github.com/haifengkao/podasset
Last synced: about 1 month ago
JSON representation
Unable to find cocoapods resources? Here is the solution!
- Host: GitHub
- URL: https://github.com/haifengkao/podasset
- Owner: haifengkao
- License: mit
- Created: 2016-04-07T03:19:08.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-11-16T14:55:20.000Z (about 4 years ago)
- Last Synced: 2024-10-11T02:15:52.880Z (3 months ago)
- Language: Objective-C
- Homepage:
- Size: 340 KB
- Stars: 55
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PodAsset
[![CI Status](http://img.shields.io/travis/haifengkao/PodAsset.svg?style=flat)](https://travis-ci.org/haifengkao/PodAsset)
[![Coverage Status](https://codecov.io/gh/haifengkao/PodAsset/branch/master/graph/badge.svg)](https://codecov.io/gh/haifengkao/PodAsset)
[![Version](https://img.shields.io/cocoapods/v/PodAsset.svg?style=flat)](http://cocoapods.org/pods/PodAsset)
[![License](https://img.shields.io/cocoapods/l/PodAsset.svg?style=flat)](http://cocoapods.org/pods/PodAsset)
[![Platform](https://img.shields.io/cocoapods/p/PodAsset.svg?style=flat)](http://cocoapods.org/pods/PodAsset)## Usage
Why is it so painful to access the assets in CocoaPods?
Pain No More!Get the damn image:
```Swift
// Swift
import PodAssetlet bundle = PodAsset.bundle(forPod: "SomePod")
let img = UIImage(named: "SomeDamnImage", in:bundle, compatibleWith:nil)
``````objc
// Objective-C
@import PodAsset;NSBundle* bundle = [PodAsset bundleForPod:@"SomePod"];
UIImage* img = [UIImage imageNamed:@"SomeDamnImage" inBundle:bundle compatibleWithTraitCollection:nil];
```Get the damn data:
```swift
// Swift
let data = PodAsset.data(forFilename: "SomeData.dat", pod: "SomePod")
``````objc
// Objective-C
NSData* data = [PodAsset dataForFilename:@"SomeData.dat" pod:@"SomePod"];
```
Get the damn json:
```swift
// Swift
let jsonString = PodAsset.string(forFilename: "SomeDamn.json", pod: "SomePod")
``````objc
// Objective-C
NSString* jsonString = [PodAsset stringForFilename:@"SomeDamn.json" pod:@"SomePod"];
```To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Requirements
The resource bundle name, by default, is the pod name.
If not, please check the third party pod's podspec and find out the resource bundle name:
```ruby
s.resource_bundles = {
'PodAsset' => ['Pod/Assets/*.png']
}
```
In the above example, the bundle name is `PodAsset`.## Installation
PodAsset is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "PodAsset"
```## How It works
Pod Asset will search all bundles and find the correct one.
If you don't want to use PodAsset, you can still find the correct bundle by `bundleForClass:`.
If the pod is loaded as a dynamic framework, locate its bundle by:
``` objc
[NSBundle bundleForClass:[some class which is defined in your pod]]
```If the pod is loaded as a static bundle, locate its bundle by:
``` objc
[NSBundle mainBundle]
```
or
``` objc
[NSBundle bundleForClass:[some class in your app]].
```## Author
Hai Feng Kao, [email protected]
## License
PodAsset is available under the MIT license. See the LICENSE file for more info.