[NSCharacterSet lowercaseLetterCharacterSet] is to be AVOIDED

My unit tests have been failing and I’ve been trying to figure the issue out for about 7 hours now. It turns out it is

[NSCharacterSet lowercaseLetterCharacterSet]

You would think this will return a character set that only contains the lower-case letters in the alphabet. But NO NO NO NO, that’s not what this method does. Apple says:

Informally, this set is the set of all characters used as lowercase letters in alphabets that make case distinctions.

So I wrote a method that prints out all the characters inside an NSCharacterSet and passed the characters in lowercaseLetterCharacterSet to this method and guess what characters I got? Here is the screenshot of my console output.

To solve this issue, avoid using that method. Instead, do this:

[NSCharacterSet characterSetWithCharactersInString:@”abcdefghijklmnopqrstuvwxyz”]

I hope this will help you save hours of head scratching.

Verify the transactionReceipt of SKPaymentTransaction

The transactionReceipt property of the SKPaymentTransaction class in StoreKit framework in iOS SDK is of type NSData and Apple isn’t very eager to tell us what it contains and what format of data it is in. However, Apple provides a service through which you can verify if this data is valid or not.

The process is explained in In-App Purchase’s Verifying Store Receipts page. But to make things easy, I have created an iOS SDK 5.0 compatible class which will do this for you. All you have to do is to pass the NSData transactionReceipt of an instance of SKPaymentTransaction to this class and wait for the response to come back.

I’ve named this class “SKTransactionReceiptVerifier” and you are free to use it in your projects or modify it to suit your needs.

You can download “SKTransactionReceiptVerifier” by clicking on this link. I hope this will help save your time.

Xcode 4.3.1 cannot attach to iOS Simulator (SOLVED)

So I downloaded Xcode 4.3.1 with the latest iOS SDK from the App Store and I’m not impressed at all. While Xcode 4.3.1 can run my old iOS apps in iOS Simulator without a problem, any new project created with this version of Xcode cannot be attached as a debug process to iOS Simulator at all. What does that mean? It means I have to wait endlessly for my apps to run on the simulator and at the end, they simply don’t run. I will end up with a black screen and the Xcode’s top bar keeps saying “Attaching to …” the app name…

Have you come across this problem?

Update 1 (Solution):

I managed to find the issue. The problem is with LLDB. LLDB is the default debugger which Xcode 4.3.1 chooses for every new iOS app. Once I changed my debugger from LLDB to GDB, I can run and debug my iOS apps on iOS Simulator. I hope this will be of help to those facing the same issue.