iOS load resources from a bundle - bundle

I've just a little problem with Xcode. From an existing project I've derived a static library (with source code) and a *.bundle (inside there's only a storyboard and images used in the storyboard). In the second project, I've linked the library (it works properly) and the bundle (in the copy bundle resources of build phases there's the *.bundle). When I try to load the storyboard, it loads it but without the images.
There's the code where I call the storyboard:
UIStoryboard *story=[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle bundleWithIdentifier:#"MYCOMPANY.BUNDLE1"]];
MyViewController *libViewContr= [story instantiateInitialViewController];
libViewContr.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:libViewContr animated:YES completion:nil ];
Thank you to everyone.

I had a same problem. I found out the png assets are compressed to .tiff format while building the bundle. you can disable this by setting 'Combine High Resolution Artwork' in the target settings to FALSE/NO.

Related

how app extension can access the containing app images/assets/resource data

I implemented the document provider app extension feature with my own
ios app. The problem is the app extension was not able to access the
containing app images/assets or the containing apps resource data.
Does any one knows how to achieve it?.
The extension has its own target in your Xcode project. In order to access resources in the extension you also need to add them to that target (in the File Inspector also check your extension target in the Target Membership section). Just be aware that those resources also get copied into the extension bundle, which increases your overall app size.
Sidenote: In my extension I didn't add my default image asset catalogue (Images.xcassets) to the extension, but was still able to access the containing images. Maybe that's an exception.
UPDATE
If you are supporting iOS 8 and up, you can create a framework to share among your app and it's extensions, and embed resources, strings, etc. inside of it. Make sure to use the [UIImage imageNamed:inBundle:compatibleWithTraitCollection:] and NSLocalizedStringFromTableInBundle methods, passing in the bundle that is your framework.
PREVIOUS ANSWER
Given that extensions are (and hopefully always will be) in a sub-folder of the main app at /Plugins/PluginName and have permissions to access files just like the main app, you can do the following (and I do in some of my apps on the store):
// image
UIImage* image = [UIImage imageNamed:#"../../image_name.png"]
// data
NSString* path = [NSHomeDirectory() stringByAppendingPathComponent:#"../../file.json"];
NSData* data = [NSData dataWithContentsOfFile:path];
This will save you a lot of space, especially if your extension uses a lot of images.

Unable to test the Live rendering in Xcode 6

Recently I have downloaded the new XCode 6 beta version.In the apple docs it is saying that we can see the output while editing the Code in .swift file without build and run. I haven't find any ways to fulfill the live rendering. Could you please help me out on this? Thanks in advance
It's important that you set up your project as a cocoa touch framework!
Then:
1.) Add #IBDesignable to your custom UIView before the class definition. (It might be helpful to override the drawInRect function for the beginning.)
2.) Add a UIView object to your .xib or .storyboard file at it change its class to your customView with the #IBDesignable attribute.
It should work.
Tipp: Check out this years WWDC video: "What's New to Interface Builder in Xcode 6" - There is explained how to set it up.
You actually do not have to create Cocoa Touch framework. If you create a custom view with nib that contains UI elements and show them another view just add the code below to your custom view
-(instancetype)initWithFrame:(CGRect)frame{
#if !TARGET_INTERFACE_BUILDER
self= [super initWithFrame:frame];
if(self){
}
return self;
#else
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
return [bundle loadNibNamed:NSStringFromClass([self class]) owner:self options:nil][0];
#endif
}
Since you don't have your main bundle while you are on design mode, you won't be able to retrieve your custom view to render. In addition to this, if you have extra properties and set them onto your ui elements, you may do this within method
-(void)prepareForInterfaceBuilder{
}
This is my solution Custom View
Custom View
Live Render (Objc)
Live Render (Swift)
Another solution How to make awesome UI components in iOS 8 using Swift and XCode 6.
(Swift, didset,live render)

Adding multiple Cib / Xib files in Cappuccino

Currently I'm working on a product that uses the Cappuccino Framework and the Objective-J language.
I created my project using this command after installing Cappuccino: capp gen -t NibApplication Myapp
The Problem I'm facing is that I want to keep my code and GUI clean.
By doing so I wanted to split the GUI up in separate Xib / Cib (compiled version Cappuccino can read) and separate controllers, like I do with iOS and Mac apps.
I couldn't find on the internet or on the docs how to do so.
Also, all the examples (including the NibApplication template) contains only 1 xib file.
In short what I'm after is to load a controller, based on a XIB file which holds the window. All the outlets are connected to the controller I loaded.
Is there anyone who knows how to do it?
Thanks in advance and have a nice day!
The typical way to do this is to use a CPWindowController or a CPViewController for each xib you want to load. Here's what it might look like:
var myViewController = [[CPViewController alloc] initWithCibName:"mynib" bundle:[CPBundle mainBundle]];
This would load Resources/mynib.cib from your main bundle. Normally you'd also subclass CPViewController so as to give yourself a convenient spot for your control code.
Fixed it myself! I used this tutorial: http://vimeo.com/8948460
But instead of using atlas I used XCode. Just follow the steps but with XCode and you'll be fine if you want the above to happen.

How to localize image with the same name?

I localized one image named "background.png". I can see there are two images with the same name but for different language. How do I load the image? Just the same as before?
backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background.png"]];
It seems that it does not work?
Assuming you've placed the image in one of the lproj folders, no code change is required. The OS will pick the correct one for the user's language settings.
You can have Xcode move an image into an lproj folder by selecting it in the project navigator, showing the File Inspector, and clicking the "Make localized" button.
For more information, see Image, Sound, and Video Resources.

Creating a static framework that uses Xibs...how to?

I have a need to create a packaging of UI classes that can be included in an XCode4 integration project by a developer and then get instantiated through the use of a config file in conjunction with NSClassFromString - a static plugin.  I have had success with creating libraries that contain UIViews that layout based on code.  Now I am trying to allow the developer to create UIs based on xib files and other resources.  I am implementing the most basic version of this...a UIViewController loading a xib file created directly through the "new file" wizard in XCode4.  The only modification I am making is adding a label to the UI in the xib.  
I am having problems getting the xib loaded.  If I include the xib in the integration project all is well. When I create the UIViewController from the library it finds the xib in the root of the app bundle and loads it.  However, this is very cumbersome during the build of the integration project, I would like to be able to just link to the library and not have to add each xib to the integration project individually.  Additionally the use of the root of the application bundle is bad because there is no directory structure that could facilitate multiple static plugins.  I have tried creating a folder that the integration project can include during its build and the xibs for the static plugin can just be dumped into folder prior to build.  If I do this the xib gets into the app bundle but when the UIViewController class loads up it cannot find the xibs.  I have been unable to code a solution to get the UIViewController to initWithNibName:bundle: properly when the xibs are in the sub-folder.  
My last attempt has been to create a static framework using this article: http://simplyitinc.blogspot.com/2011/04/creating-static-framework-in-xcode-4.html . That seems to get me a framework I can link against and the xib is in that framework directory but ... the xib does not get placed into the app bundle when I link against the framework.  My classes are available but fail to load the xib, obviously because it is not in the app bundle.  
Any suggestion on how this requirement might be accomplished?  

Resources