Does anyone know exactly what the new (iOS 6) lowercaseStringWithLocale method of NSString does? The documentation is very skimpy, and I didn't find a single reference to this method in Apple's developer forums.
While localizing my app, I'm interested in changing words from my strings file to lowercase when they appear in a sentence -- except in the German version, where some words should stay in uppercase at all times. Is that what this method is for? Or something completely different?
The discussion in lowercaseString might shed some light:
Note: This method performs the canonical (non-localized) mapping. It is suitable for programming operations that require stable results not depending on the user's locale preference. For localized case mapping for strings presented to users, use the corresponding lowercaseStringWithLocale: method.
So if you're computing the lowercase version of a string for a purpose such as case-insensitive database lookup, use lowercaseString. If you intend to show the user the result, then use lowercaseStringWithLocale.
Note that lowercaseStringWithLocale won't make a decision based on the actual words as to whether the word should be lowercased or not. It does what you ask it to do, and doesn't question your motives.
Lower/uppercasing is indeed locale-dependent. The only example I know about (and it's a killer one, a source of many globalization bugs) is the Turkish i issue. See here for an overview: http://www.codinghorror.com/blog/2008/03/whats-wrong-with-turkey.html
Basically, when you uppercase "Hi" you get "HI" except for Turkey where you get "Hİ"
Likewise, when you lowercase "HI" you get "hi" except for Turkey where you get "hı"
Related
Curious to know if Swift permits the use of search operators like the wildcard "*" or the exclusive "-" or Boolean search operators like AND, OR and NOT. By search operators I mean symbols an app user would input into a text box to narrow a search. I think NSPredicate's LIKE allows the use of "*" and "?". But I have not come across online examples of search operators used in connection with swift's often cited filtering code:
object.filter{$0.objectProperty.contains(searchText)}
If someone could point me in the right direction of some literature I would be grateful. I would be interested to learn how to make it possible for an app user to use search operators referenced above and/or use something like the following to narrow a search: dog w/20 food
The latter search term would find all instances of "dog" within 20 characters of "food."
The filter on Swift's array Is simply a method that returns it's own type, using a passed function that returns a Bool. So the short answer is, there's nothing related to the "filter" function that allows you to do anything like what you're talking about.
One common way to filter/find things is to use Regular Expressions which are supported by Swift. (You can search here for more specific info).
If you have everything in a database and expect your users to know how to write Predicates, I suppose you could use CoreData and search with a string from the user, but that seem pretty unlikely.
Outside of those options you will probably need to search for a third party library or build some sort of parser yourself.
I have googled (well, DuckDuckGo'ed, actually) till I'm blue in the face, but cannot find a list of language codes of the type en-GB or fr-CA anywhere.
There are excellent resources about the components, in particular the W3C I18n page, but I was hoping for a simple alphabetical listing, fairly canonical if possible (something like this one). Cannot find.
Can anyone point me in the right direction? Many thanks!
There are several language code systems and several region code systems, as well as their combinations. As you refer to a W3C page, I presume that you are referring to the system defined in BCP 47. That system is orthogonal in the sense that codes like en-GB and fr-CA simply combine a language code and a region code. This means a very large number of possible combinations, most of which make little sense, like ab-AX, which means Abkhaz as spoken in Åland (I don’t think anyone, still less any community, speaks Abkhaz there, though it is theoretically possible of course).
So any list of language-region combinations would be just a pragmatic list of combinations that are important in some sense, or supported by some software in some special sense.
The specifications that you have found define the general principles and also the authoritative sources on different “subtags” (like primary language code and region code). For the most important parts, the official registration authority maintains the three- and two-letter ISO 639 codes for languages, and the ISO site contains the two-letter ISO 3166 codes for regions. The lists are quite readable, and I see no reason to consider using other than these primary resources, especially regarding possible changes.
There are 2 components in play here :
The language tag which is generally defined by ISO 639-1 alpha-2
The region tag which is generally defined by ISO 3166-1 alpha-2
You can mix and match languages and regions in whichever combination makes sense to you so there is no list of all possibilities.
BTW, you're effectively using a BCP47 tag, which defines the standards for each locale segment.
Unicode maintains such a list :
http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/index.html
Even better, you can have it in an XML format (ideal to parse the list) and with also the usual writing systems used by each language :
http://unicode.org/repos/cldr/trunk/common/supplemental/supplementalData.xml
(look in /LanguageData)
One solution would be to parse this list, it would give you all of the keys needed to create the list you are looking for.
http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
I think you can take it from here http://www.unicode.org/cldr/charts/latest/supplemental/territory_language_information.html
This can be found at Unicode's Common Locale Data Repository. Specifically, a JSON file of this information is available in their cldr-json repo
We have a working list that we work off of for language code/language name referencing for Localizejs. Hope that helps
List of Language Codes in YAML or JSON?
List of primary language subtags, with common region subtags for each language (based on population of language speakers in each region):
https://www.unicode.org/cldr/charts/latest/supplemental/language_territory_information.html
For example, for English:
en-US (320,000,000)
en-IN (250,000,000)
en-NG (110,000,000)
en-PK (100,000,000)
en-PH (68,000,000)
en-GB (64,000,000)
(Jukka K. Korpela and tigrish give good explanations for why any combination of language + region code is valid, but it might be helpful to have a list of codes most likely to be in actual use. s-f's link has such useful information sorted by region, so it might also be helpful to have this information sorted by language.)
Why do we use a reversed URL identifier like com.yourcompany.noname within Xcode?
Same as in Java - to uniquely identify ourselves. The assumption is that if you have a URL, no-one else would use the same string.
Now why it's reversed, it's guesswork, but I'd say the question is wrong: it's the hostnames that originally got it "wrong" starting with the most specific thing, and it perpetuated down the history. URL of the form http:com.yourcompany.noname/bigdir/littledir/file#fragment would make much more sense(*), where you start with the most global thing, and end up with the tiniest detail, just like when reading time, or arabic numerals.
(Most date formats also did this wrong - the only logically consistent format is YYYY/MM/DD, if we use numbers like we do, with the smallest unit on the right).
*) Also, the creator of the URL, if I remember correctly, is on the record for saying that his biggest regret is the two slashes. EDIT: found it
Let's think about it philosophically for a moment.
Consider the case of normal URLs, e.g. noname.yourcompany.com. The highest level domain for this URL is com, since it's included in a gigantic set of other URLs besides the one you're given. For instance apple.com and microsoft.com both belong to the com top level domain. Then, yourcompany is the next highest level domain, since it belongs to your company and not Apple or Microsoft, but may itself include subdomains of its own.
In this respect, we can see that when we follow what we call 'normal URLs' from top to bottom, we are actually reading right to left. In programming languages, when we're doing scope resolution, we want to read left to right, because that's the direction in which most of us write code, and we usually start from broad categories and narrow down when we're trying to find that one elusive function we might be looking for.
That's why, in a namespace scheme that's designed to be resemble Internet domains, we end up with names that look backwards. In a certain sense, it's the Web addresses that are "wrong".
I am doing another iOS application and I wonder if there are any naming conventions or good practices on how to name actions that I could follow. I am thinking of names on the functions that are invoked when user e.g. touches a button.
Go with Apple's guidelines. What were in the past good suggestions have now been codified in ARC (Automatic Reference Counting) and are necessary to be followed for ARC to generate correct code. Using these guidelines may well future-proof your code, it did for ARC!
Apple's guidelines
Coding Guidelines for Cocoa
From the method naming section:
Start the name with a lowercase letter and capitalize the first letter of embedded words. Don’t use prefixes.
There are two specific exceptions to these guidelines. You may begin a method name with a well-known acronym in uppercase (such as TIFF or PDF)), and you may use prefixes to group and identify private methods
For methods that represent actions an object takes, start the name with a verb.
- (void)invokeWithTarget:(id)target;
- (void)selectTabViewItem:(NSTabViewItem *)tabViewItem
Do not use “do” or “does” as part of the name because these auxiliary verbs rarely add meaning. Also, never use adverbs or adjectives before the verb.
If the method returns an attribute of the receiver, name the method after the attribute. The use of “get” is unnecessary, unless one or more values are returned indirectly.
- (NSSize)cellSize;
Use keywords before all arguments.
- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag
Make the word before the argument describe the argument.
- (id)viewWithTag:(int)aTag;
I haven't come across much in the way of specifics when it comes to naming conventions for IBActions. However, if you were to follow the trend Apple seems to be setting in its sample apps, then some examples are as follows:
-(IBAction)cameraAction:(id)sender;
-(IBAction)done:(id)sender;
-(IBAction)takePhoto:(id)sender;
Hope this helps.
I guess any method name in Objective - C should be readable like you reading an english sentence. Lets say below method.
[fileWrapper writeToFile: path atomically: YES updateFilenames: YES];
// This is not a real example but purpose of sharing is to make sure
method name is readable, so programmers can actually read code and can
have SmallTalk.
When you read left to right it helps you to read and explains it self what it is going to do.
Check out this below link,
http://cocoadevcentral.com/articles/000082.php
Jump on page No. 5 of 7
There are lots of tips has been given. More tips can be found in Apple's developer library.
Happy Coding
Here is a discussion about how to name IBAction functions/methods.
I was discussing this with some friends and we began to wonder about this. Could someone gain access to URLs or other values that are contained in the actual objective-c code after they purchase your app?
Our initial feeling was no, but I wondered if anyone out there had definitive knowledge one way or the other?
I do know that .plist files are readily available.
Examples could be things like:
-URL values kept in a string
-API key and secret values
Yes, strings and information are easily extractable from compiled applications using the strings tool (see here), and it's actually even pretty easy to extract class information using class-dump-x (check here).
Just some food for thought.
Edit: one easy, albeit insecure, way of keeping your secret information hidden is obfuscating it, or cutting it up into small pieces.
The following code:
NSString *string = #"Hello, World!";
will produce "Hello, World!" using the strings tool.
Writing your code like this:
NSString *string = #"H";
string = [stringByAppendingString:#"el"];
string = [stringByAppendingString:#"lo"];
...
will show the characters typed, but not necessarily in order.
Again: easy to do, but not very secure.
When you purchase an app it is saved on your hard disk as "FooBar.ipa"; that file is actually in Zip format. You can unzip it and inspect the contents, including searching for strings in the executable. Try it! Constant values in your code are not compressed, encrypted, or scrambled in any way.
I know this has already been answered, but I want to give my own suggestion too.
Again, please remember that all obfuscation techniques are never 100% safe, and thus are not the best, but often they are "good enough" (depending on what you want to obfuscate). This means that a determined cracker will be able to read your strings anyways, but these techniques may stop the "casual cracker".
My other suggestion is to "crypt" the strings with a simple XOR. This is incredibly fast, and does not require any authorization if you are selling the app through the App Store (it does not fall into the categories of algorithms that require authorization for exporting them).
There are many snippets around for doing a XOR in Cocoa, see for example: http://iphonedevsdk.com/forum/iphone-sdk-development/11352-doing-an-xor-on-a-string.html
The key you use could be any string, be it a meaningless sequence of characters/bytes or something meaningful to confuse readers (e.g. use name of methods, such as "stringWithContentsOfFile:usedEncoding:error:").