views:

1158

answers:

1

I have an app on the store which was built for 3.1.2, but which was crashing under 4.0GM. I've fixed the crash problem using Xcode 3.2.3, but was also getting warnings that such-and-such class did not implement NSXMLParserDelegate. I added to the headers and everything seemed fine. I've now submitted the app and it's waiting for review. This latest version was compiled with base SDK of 4.0, and a deployment target of 3.1.2.

The problem I have is that this morning I opened up the project in Xcode 3.2.2, and when building against base SDK of 3.1.2, I'm getting compile errors saying that NSXMLParserDelegate does not exist. Does this mean my app that is waiting for review is going to crash under 3.1.2 devices? This is strange, because my beta testers who are using 3.1.3 and I think 3.1.2, said the app works fine. Shouldn't it crash if it can't compile against base SDK of 3.1.2?

I think this should be ok to discuss in regards to the 4.0 NDA, as my problem is specific to 3.1.X.

+2  A: 

First of all, the NDA has been lifted this week, so no problem to discuss the iOS 4.0 SDK.

As for your question: there's a difference between compiling and running an application.

The NSXMLParserDelegate protocol was added in the iOS4 SDK. In previous versions of the SDK, the XML parser delegate methods were declared in a category. In iOS4, these methods have been moved to a dedicated protocol, which makes it a litte cleaner. At runtime, there's no difference. Once compiled, the app doesn't know anything about protocols or categories. The NSXMLParser will simply check if a specific delegate method is implemented (via respondsToSelctor), so it will run just fine.

In general, it's not a problem to build with iOS4 SDK and run on 3.0. You do have to make sure you don't call any methods that don't exist in 3.0. This is very easy to do by calling respondsToSelector. It allows you to create a single app that runs on all OS versions, but still allows you to call 4.0-specific methods.

I hope this makes sense ...

Philippe Leybaert
Makes sense, and thank you for the explanation. All clear.
alku83
So how could we add <NSXMLParserDelegate> in interface declaration without getting errors in older version.. what is the category class that has NSXMLParserDelegate in old os..
Tharindu Madushanka
Simply add the protocol to your parser class. You will not get errors when you run it on 3.0. As I said, the app doesn't know anything about protocols or categories when it's running. It's just a compiler thing.
Philippe Leybaert