Read User-Defined Settings from custom .plist file - swift

I should use different API keys for different schemes (like Debug, QA, Release).
And I want to use a custom .plist file for that (Config.plist). Not other ways because of my project's architecture.
I configured User-Defined Settings in Build Settings
I followed these steps:
Create a custom User-Defined Settings named MY_API_KEY,
Add API key to different schemes,
Create a new Config.plist's User-Defined Settings for read from Info.plist,
Write CONFIG_FILE to Info.plist,
Write MY_API_KEY to the custom plist (Config.plist),
So I want to read MyAPIKey value from Config.plist but it returns ${MY_API_KEY} as a String.
Expected result is "asdfsadf" (value from User-Defined Settings).
NOTE:
I didn't post my way for read values from plists because I'm using my custom services for read plists.

First of all, you should use parentheses instead of curly braces:
So change this:
${MY_API_KEY}
${CONFIG_FILE}
to this:
$(MY_API_KEY)
$(CONFIG_FILE)
And second of all, why you don't use different info.plist files for different environments?
You can use info.plist File attribute to assign different plist files for different environments:
So you can have entirely custom plist file per environment.

Related

How to introduce new stream format in beanio

Is beanio can support more stream format other than csv, fixedLength, delimited, json and xml? I have created a new module from beanio to add new format, But the beanio.properties used by StreamCompiler to map the format is resides in the beanio parent project, how will I add a new format to it?
I don't know if you can extend BeanIO this way, but it would be great if this works for you.
See Section 8 of the reference documentation on how to provide your custom beanio.properties file
8.0. Configuration
In some cases, BeanIO behavior can be controlled by setting optional property values. Properties can be set using System properties or a property file. BeanIO will load configuration setting in the following order of priority:
System properties.
A property file named beanio.properties. The file will be looked for first in the application's working directory, and then on the classpath.
The name and location of beanio.properties can be overridden using the System property org.beanio.configuration. In the following example, configuration settings will be loaded from the file named config/settings.properties, first relative to the application's working directory, and if not found, then from the root of the application's classpath.
java -Dorg.beanio.configuration=config/settings.properties example.Main
Please let us know if you can extend the formats supported this way.

Localization workflow for updating development language

I have a project where I've setup localization using NSLocalizedString with keys instead of actual values for text parameters, i.e. something like this:
NSLocalizedString("RunningDistance", "distance for a marathon")
instead of this:
NSLocalizedString("Running distance.", "distance for a marathon")
Then, I exported them to xliff for translation and imported back; and it's all working.
Now, I want to add new strings (and lots of them).
I read that it is currently not recommended (and supported) to use genstrings for swift.
I thought I should export the development language to xliff, add translations and reimport. I tried this and I get the The XLIFF file does not contain a target language error.
Does this mean I need to add all those strings manually into Localizable.strings and elsewhere (as I'm using base localizations)?
Is there any other way to get this done, and import my base language xliff?

Is it possible to store NSLocalizesStrings in plists?

This may seem like a stupid question. But I have a plist for different categories in a iPhone application.
categories.plist
<key>cat1</key>
<string>Players</string>
...
Is it possible to localize this strings? This categories are created in to Core Data when the app is started for the first time. And if the user changes language after first launch the category names will still be in the language as when the application was first launched.
Is it possible in some way to localize the strings in the plist?
You can easily localize the entire file. Just select the file in Xocde and click the + button in the Localization section of the File Inspector to add multiple languages. You can then translate the file for each language.
If you just want to translate the strings, I would put keys into the plist file and translate those keys via the normal Localizable.strings file. In your code, you would then not use the strings directly but translate them first with NSLocalizedString().
you would typically create a plist file for each localization (not individual keys).
since that would duplicate the categories in each localization and in many cases only the translations change (not necessarily other keys), you could work around this if you use a separate lookup table (plist) for the localized translations of the values in the category plist. then you would use the category plist keyed values as keys for another localized lookup table (which would need only strings).

Xcode - exclude files in a custom configuration - better way?

I'm trying to come up with a way to make it easy to switch out our "mock" data services and our live ones. Basically, we'll have live servers with real web services, but for whatever reason, a developer may want to load data from static files (file urls).
I figured I would solve this problem by creating categories that override the methods that fetch the data, thus leaving original code untouched (it has no concept of the "mock" data). I don't want to litter my code with #ifdef.
I can put an #ifdef at the very beginning of each file that has categories in it, and I can set a custom flag in the configuration settings, but I'd rather just have a way to include or exclude the files depending on the configuration. Is that possible? How do you solve this problem?
See http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html
The trick is to define EXCLUDED_SOURCE_FILE_NAMES in the configuration you want to exclude the files from, and set the value of that custom build setting to a list of the file names (or a pattern that matches those, and only those, file names).
I would recommend creating two targets one of which has the mock categories included and another one which does not.
When you want to test, just build the target containing the mock categories. Everything else can remain identical.
If you would like to add a file but do not wont to compile it. Go to (for all your targets) project>build phases>compile source and take out the file that you do not want to compile.

What is the use of plist?

In my application, I am using a plist. Please, can anyone explain what are the uses of plist with an example or a sample code?
In the context of iPhone development, Property Lists are a key-value store that your application can use to save and retrieve persistent data.
All iPhone applications have at least one of these by default, the Information Property List:
The information property list is a
file named Info.plist that is included
with every iPhone application project
created by Xcode. It is a property
list whose key-value pairs specify
essential runtime-configuration
information for the application. The
elements of the information property
list are organized in a hierarchy in
which each node is an entity such as
an array, dictionary, string, or other
scalar type.
Plist are XML files in a specific format. Prior to XML, they had a custom format now called 'old plist'. (You almost never see that anymore save in legacy code.)
Foundations collection classes automatically generate XML files in the plist format when you use their serialization methods to write them to disk. They also automatically read them back. You can also write your own serializers for your own custom objects. This allows you to persistently store complex objects in a robust, human readable format.
One use for plist for programmers is that it is easier to use the plist editor to input and manage a lot of data than it is to try and code it. For example, if you have an class that requires setting a large number of ivars, you can create a plist, read it into an NSArray or NSDictionary and then initialize the instance by passing it the dictionary.
I use this technique when I have to use a large number of paths to draw complex objects. You define the path in the plist file instead of the code and edit the path in the plist editor.
It's also a handy way to create a large amount of detailed test data.
PList means PropertyList
It is XML file format
It is mainly user for store and reterve the data
It can store the key-value pair
It's been a long time since I've looked at them, but plist is a short-form of "properties list" and can be used to store application configuration settings that need to persist between instances of an application's execution. Could be similar to a .properties file (I see those a lot on Java projects).
A plist is essentially just a data file, it stores information in a documented format.
From Wikipedia:
In the Mac OS X Cocoa, NeXTSTEP, and
GNUstep programming frameworks,
property list files are files that
store serialized objects. Property
list files use the filename extension
.plist, and thus are often referred to
as plist files. Property list files
are often used to store a user's
settings. They are also used to store
information about bundles and
applications, a task served by the
resource fork in the old Mac OS.
.plist
Info.plist is key/value persistence storage(property list) which is used by system and user. It contains user-friendly text in XML format. Info.plist is mandatory file for any Bundle. For example it contains Bundle id[About] which is usually is used by system but as a programmer/user you are not limited on changing/reading[More]. The same as you can add K/V for your own purposes and read it in runtime. You could noticed that some frameworks forces you to add K/V into your's application to identify you or some other cases.
.entitlements is a property list with enabled capabilities(e.g. ApplePay)
[Info.plist location]
[Vocabulary]