Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cocoa touch framework assets not visible in App Project

I've been trying since morning creating a cocoa touch farmework to put my self containing widget inside it, and to allow any app I'm working on to use it in the future.

I've managed to build the project and export .framework file, but all the assets are not showing now. all my Images are inside assets catalog.

And they seem to be exported since the .framework file has (assets.car) file inside it.

I'm currently accessing them using

UIImage* icon = [UIImage imageNamed:@"iconName"];

But it always returns null, Any ideas ?

like image 310
Mr.Me Avatar asked Nov 06 '14 15:11

Mr.Me


People also ask

What is asset catalog?

An asset catalog is a type of file used to organize and manage different assets and image resolutions used by your app's user interface.

What is Cocoa Touch static library?

Cocoa Touch Static Library. A. A static library is a collection of compiled source files which is then linked directly into an app's binary. That is, it becomes a part of your app's binary.

What is Cocoa Touch class in Xcode?

Cocoa and Cocoa Touch are the application development environments for OS X and iOS, respectively. Both Cocoa and Cocoa Touch include the Objective-C runtime and two core frameworks: Cocoa, which includes the Foundation and AppKit frameworks, is used for developing applications that run on OS X.


1 Answers

You can supply the framework bundle when creating an image. In Swift 2:

class func getMyImage() -> UIImage? {
    let bundle = NSBundle(forClass: self)
    return UIImage(named: "YourImageName", inBundle: bundle, compatibleWithTraitCollection: nil)
}

Swift 3:

class func getMyImage() -> UIImage? {
    let bundle = Bundle(for: type(of: self))
    return UIImage(named: "YourImageName", in: bundle, compatibleWith: nil)
}

Here is a demo project containing a framework with an image and an app that uses it.

https://github.com/marketplacer/AssetFrameworkDemo

like image 92
Evgenii Avatar answered Sep 30 '22 08:09

Evgenii