iPhone SDK: Localization of external class files? - xcode

I am adding some external classes to my already-localized project that include their own localization strings. For some reason the localization isn't working in these classes. It should be noted that I am not copying the external class files to my project, just adding a reference to them. I thought the problem could be that the external string file couldn't have the same name as the projects string file -- Localizable.strings -- so I changed it to something unique for the class. This didn't help. I also tried dragging the classes string files directly to the "Copy Bundle Resources" of my project to make sure that the strings in the bundle. Still no luck.
Interestingly, if I add these localized classes to a different project that isn't yet localized -- e.g. there isn't any Localizable.strings file in the project -- the class localizations work fine.
Suggestions?

You should use NSLocalizedStringFromTable instead of NSLocalizedString to extract strings from tables other than the default Localizable.strings.

Related

Imported subclasses not recognised

I'm trying to use the CVCalendar framework but Xcode doesn't seem to recognise the files, so perhaps I am importing them wrong.
In Storyboard however I can change a views class to any of the CVCalendar subclasses, it's just in my view controller that the files aren't recognised and when linking my storyboard views I'm getting undeclared type errors.
The instructions were to simple copy the folder containing all of the swift files into my project which I did and copied if required.
Did I miss something?

ios iphone xcode renaming a built custom framework

Have a custom built framework using custom template, etc. Works great. But would like to copy the framework after the build something like.
/dir1/myframework.framework
to
/dir2/myframework-5.1.framework
When the renamed one is included in the xcode program, all is well (framework search path is correct, etc), but the link does not see the framework. Have tried to change the renamed info.plist items with no luck. What could be missing... I thought this was done before, but can't seem to get it working now. is this a signing thing from the framework build?
Changed the following plist items
bundle name myframework-5.1.framework
executable file (changed file name)
etc.
Turns out you have to rename the object link in the framework to the same name as the framework and all is ok.

Why is Xcode not prefixing filenames?

When I start an iOS single view application project, the AppDelegate files and ViewController files are not prefixing with the project name like they used to.
files names are as follows when I open a new project:
AppDelegate.h
AppDelegate.m
MainStoryBoard.storyboard
ViewController.h
ViewController.m
Why is this?
You have to add it manually. When you create a new project just fill out the "Class Prefix" field on the screen where you name the project/bundle id/ etc..
Just add your prefix where I wrote "THIS IS THE PREFIX" in the screenshot below
If you want to add a prefix after you've created your project, you can do so in the file inspector on Xcode's right pane:
Personally, I prefer not to prefix class names within an application.
When you are writing code for libraries, or custom classes, or categories, they are recommended, as there aren't namespaces in Objective-C.
But for application classes, I find they are just noise. Looking down a list of files that all have the same three letters in the front makes it just a bit harder to find what I'm looking for.
I mean, are you really going to have more than one class called AppDelegate? I'm all for full and descriptive naming of my classes, but prefixes for all the classes doesn't help me.
If it helps there are a few conventions for writing code. Search and you'll find them. Here are mine, for example.
You don't have to follow them, but pick a style and be consistent with it.
XCode 8 does NOT have the 'Class Prefix' field. It only has 'Product Name' and this does not ripple down to the view controller or the app delegate. I think 8.3 has bugs.
Class Prefix is file & template business. For the sake of organised files in a project it makes sense to have filenames that express their contents.
The workflow to achieve that was actually simplified with the Class Prefix field in the File inspector panel while your project name is active (clicked) in the file browser.
When there is a class prefix set the class name field when creating new files is predefined. That way you can choose file by file (class by class) if you want to use it and class name and file name will result in similar name scheme.

Xcode - change project templates

So I can add new templates for single files, but I want Xcode to uses these files when setting up the new project (most noticeably the Controller and Delegate .h and .m files). How do I do that?
In addition to the templates for individual classes that you found, there are also templates for the various project types. If you just want to replace a single class file that is already being added in the projects you can just replace the file in each of the project template files (as long as the names are the same). You will need to copy the template files into each project template that you want to change it in. The other option is to make your own project templates with whatever default files you want.

Best way to deploy and reference an XSLT file

In a visual studio project I have three layers, Data Layer, Business Layer and Presentation Layer.
In the Data Layer I have a few XSLT's that transform some objects into an email, all works fine but I have discovered that the XSLTs do not get built/copied when building.
I have currently, created a folder in the deploy location and placed the XSLT's there but I am concerned about relying on a manual process to update these.
Has anyone encountered a similar issue and if so how did they get around it.
It smacks of changing the MSBuild script to copy the build artifacts to the required location, does anyone have examples of this?
Thaks
If you are using Visual Studio 2005/2008, the easiest way to do this is by including your XSLT files as project resources.
Open the Properties for your project.
Select the Resources tab. You will probably see a link that says "This project does not contain a default resources file. Click here to create one." Go ahead and click on that.
Click the Add Resource drop-down near the top and select Add Existing File.
Browse to your XSLT files and select them.
After you have done this, you can easily access the resources in the following manner:
// To get the contents of the resource as a string:
string xslt = global::MyNamespace.Properties.Resources.MyXsltFile;
// To get a Stream containing the resource:
Stream xsltStream = global::MyNamespace.Properties.Resources.ResourceManager.GetStream("MyXsltFile");
If you are using Visual Studio 2003, your best bet is to include those XSLT files as embedded resources for the DLL. In Visual Studio, select the file(s) in Solution Explorer, open the Properties pane, and change the Build Type to "Embedded Resource". You can then use the GetManifestResourceStream method to get a Stream containing the XSLT(s). The name to pass will be based on the default namespace of your assembly, the folder containing the file, and the name of the file.
For example, say your data layer assembly has a default namespace of My.DataLayer. Within your data layer project you have a folder named Templates which contains a file called Transform.xslt. The code to get your XSLT would look like this:
// There are numerous ways to get a reference to the Assembly ... this way works
// when called from a class that is in your data layer. Have a look also at the
// static methods available on the Assembly class.
System.Reflection.Assembly assembly = (GetType()).Assembly;
System.IO.Stream xsltStream = assembly.GetManifestResourceStream("My.DataLayer.Templates.Transform.xslt");
For more information check out this article on CodeProject.
Obvious question maybe, but still has to be asked, did you include the folder containing the XSLT's in the project itself? Is this a web or forms app?
In VS, it is easy to set the properties of the XSLT files in the project to copy on build, by default they do not.
I may have explained myself poorly.
THe Data layer is a class library that a the presentation layer references.
On building the DataLayer I can get the XSLTs to output to the Bin directory of the DataLayer. However when I build and publish the presentation layer, it correctly grabs the DLL but not the XSLTs

Resources