Using images from a static Library - objective-c

I'm trying to convert a project, which has images, into a static library.
The code that gets the image is as follows:
[UIImage imageNamed:#"foo.png"]
When I include this library into another project, the image doesn't load. However, if I copy the images into the new project, then it does load.
Is there any way I can get this to work where the images are only contained in the library and I don't have to copy them over to my project?
By the way, my Header Search Paths contains the path to where these images are located in the library, if that makes any difference.

Just prepend the name of the bundle that contains your image to the image name:
[UIImage imageNamed:#"Myframework.bundle/MyImage"
This also works in Interface Builder, the preview may be broken but the image will be properly loaded.
If using CocoaPods (which I would recommend) make sure to use the resource_bundles option for your images and Nibs.
You can see a related answer here.

A static library cannot contain bundle resource. So simply linking the .a file will not be enough. But you should be able to cross-reference the static library xcodeproj. Example

Had a similar situation to this and wrote a script to copy the files in to the .app at compile time. A similar fix to the one we use is described in the "Non-code assets for static libraries" section on this web page. This works but can cause some code signing errors. Another option is to create a second .bundle target for the resources described on this web page although for some reason I could not get the bundle to actually build. I am currently looking at writing a script to copy the resources in to a bundle at compile time and compile any .xib files to .nibs, this is also a possible solution you could look at.

Related

iOS - Execute precompiled app from a server

I'm looking for executing a .xib (with its own controllers and libraries) precompiled on a server, downloading it on runtime.
Is it possible?
Thanks!
EDIT:
So could somebody give me an example of a program that uses NSBundle that executes other app?
And how do I create the bundled application?
I don't think you can import a xib into the application's bundle at run-time (which you would have to in order for this to happen). Others may know more and correct me!
I can think of a couple of ways you could try to do this, but are you aiming to get it in to the store?
This is expressly prohibited by Apple Developer Guidelines.
A .xib file is just a data file, so there shouldn't be any problem loading one that's outside your app's bundle. I can't say I've ever tried it, but as long as it's in a bundle, you should be able to:
Create an instance of NSBundle using the path to the bundle containing the .xib you want to load. See +[NSBundle bundleWithPath:] for that.
Load the .xib using the bundle you created in the previous step with any of the normal .xib-loading methods, such as -[UIViewController initWithNibNamed:bundle:] or +[UINib nibWithNibName:bundle:].
with it's own controllers and libraries
That part won't work. iOS doesn't allow dynamic linking to frameworks other than the ones provided by the system, so there's no way to load your code. If you can build all the code you need into your app, though, you should still be able to use downloaded .xib's as described above. That would let you do things like update the way your views are laid out or what targets and actions your controls are connected to.

iPhone Generic bundle for application resources

Have developed an iPhone app which has two different functionality and it using same images and string in some areas in both the project. Here I am using preprocessor macros which are differentiating it during compile time say for example project one and project two.
Here my question is is there any way to pass the images and string in generic way. I mean if I execute the application for project one means it should only take relevant app's images and string it should not bundled with another project i.e. project two's source.
Any idea and suggestion will be greatly appreciated.
Have a look at the screenshot of a project that has two targets:
And at folder structure:
You can put shared assets in the Shared folder and add them to both targets like SharedImage.png in the example. For assets that has two different versions, you can put each version on the appropriate folder (Target A or Target B) and use the same name for both versions. For example, when adding the image MyImage.png to Target A, you simply have to check the box Target A like in the following screenshot:
Now, it is easy to use the correct asset for each target and without using preprocessor macros. For example, the following code will use the correct version of MyImage.png whether it is running in Target A or Target B
UIImage *image = [UIImage imageNamed:#"MyImage.png"];

Load JS (CSS) file from another JS (CSS) file on Objective C

I'm trying to load an entire source library of JS/CSS from Objective C (Xcode) from a UIWebView with an HTML loaded. The problem is that in the library documentation, they say you just need to load one JS file, but inside it's requiring others JS. The question is how i have to arrange the files... Just one folder with all the sources? Nested folders containing the JS/CSS just as they come on the library? or Do I need to fix the path of the requires in order to load them (say absolute or relative)?
Thanks in advance
I suggest minifying all of your JS (CSS) into 1 file. You can download tools to do this, but one easy free one online is: http://jscompress.com/
Using some command or a downloaded app would probably make the code-minify-debug process much quicker, but you can test out the idea using that online tool.

Where should I put my custom widget files in Yii framework?

From this page,
http://www.yiiframework.com/wiki/23/how-to-create-a-breadcrumb-widget/
It seems it suggests that we should put the files in the component folder. But if my widget contains javascript and css files, where should these files be placed?
By the way, is this a good idea that I create it as an extension? If I go this way, all widget files are more self-contained in a folder inside the extension folder. But since the widget I am going to work on is very customized, it's unlikely that it will be useful to other people or my other projects. Making it an extension seems a little bit strange.
I understand that it does not really matter where I put these files as long as the paths I am using in the codes are correct but I would like to know the common practice.
I think the common practice is to put the widget in extensions folder with js & css files in an folder named asset. In the php class file, you do initialization first by publishing the asset with yii asset manager.
The file structure may be like
extensions/
widget_name/
widget.class.php
assets/
plugin.js
style.css
I would join the recommendation to put the widget under /protected/extensions.
I put the assets in a slightly more detailed manner: /protected/extensions/WidgetClassName/assets/ and the widget view files in /protected/extensions/WidgetClassName/views/...
Don't forget to edit your /protected/config/main.php and add a row in the 'import' section (for autoloading of the widget): 'ext.WidgetClassName.WidgetClassName.*'

What are the steps to creating an 'executable bundle'

I'm trying to create an NSService in a Bundle project. I need to add a main and other bits of code to the actual cocoa bundle created for me by xcode.
Is this as simple as just adding an object-c class via the xcode wizard, then adding my main function to that? or is there some other magic way or other steps involved?.
Many thanks.
You can add code by simply adding source files.
A bundle normally does not have a main function since it is loaded from another executable.
thanks Nikolia - after adding the code, i also had to change the bundle type to Executable, which also allowed me to change the extension from .bundle to .service.
Now all I need to do is work out how to stop the service!