Do you need to handle compressed files on your iOS project? Then you may find the following links to compression libraries useful:
ZipKit is an Objective-C framework for reading and writing Zip archives in Mac OS X and iOS apps.
Unrar4iOS The main goal of this project is provide a port of Unrar library to iOS platform.
7-Zip LZMA SDK LZMA is the default and general compression method of 7z format. The LZMA SDK provides the documentation, samples, header files, libraries, and tools you need to develop applications that use LZMA compression.
If you are using TouchXML or GDataXML for reading XML documents, you may have run into a problem with your XPath queries. I was working with the Freshbooks API to return a list of projects and it returned some fairly simple XML (I have abbreviated all the attributes of a project element for clarity):
<?xml version="1.0" encoding="utf-8"?><responsexmlns="http://www.freshbooks.com/api/"status="ok"><projectspage="1"per_page="15"pages="1"total="5"><project><name>Super Fun Project</name></project></projects></response>
So now I wanted to simply retrieve all the project elements in the response using XPath. Seemed simple enough, so this is what I wrote:
Retrieve objects using XPath and GDataXMLDocument
// doc is an instance of GDataXMLDocumentNSArray*projects=[docnodesForXPath:@"//projects/project"error:nil];NSLog(@"%d",projects.count);
My NSLog statement always returned 0 results. This started to drive me nuts. I tried several different XPath queries and still no luck. There were no errors even when I used the error outlet, and I could even loop through the elements manually and see that there were indeed project elements being returned. So what’s the problem?
The problem had to do with namespaces. The XPath query needed to be written using the correct XML namespace, so something like this:
Adding a namespace to GDataXMLDocument
// doc is an instance of GDataXMLDocumentNSArray*projects=[docnodesForXPath:@"//ns:projects/ns:project"error:nil];NSLog(@"%d",projects.count);
Great, but what is the namespace name? According to my XML response it was http://www.freshbooks.com/api/. However the GDataXMLDocument knew nothing about it.
I started digging into the source of GDataXML and came across this in the nodesForXPath method:
Now we’re getting somewhere. Next stop the definition of the kGDataXMLXPathDefaultNamespacePrefix constant:
// when no namespace dictionary is supplied for XPath, the default namespace// for the evaluated tree is registered with the prefix _def_ns_EXTERNconstchar*kGDataXMLXPathDefaultNamespacePrefix_INITIALIZE_AS("_def_ns");
THAT WOULD HAVE BEEN HELPFUL AN HOUR AGO… Anyway, I went ahead and changed my original XPath query to:
Adding the correct default namespace to GDataXMLDocument
// doc is an instance of GDataXMLDocumentNSArray*projects=[docnodesForXPath:@"//_def_ns:projects/_def_ns:project"error:nil];NSLog(@"%d",projects.count);
BOOM. Now we’re cooking with gas. It correctly returned all my project elements. So the lesson learned here is that GDataXML and TouchXML will not register your namespace or use it by default. You have to use the default, or register it manually.
How do you register a namespace with GDataXML manually you ask?
Registering a namespace with GDataXML
// doc is an instance of GDataXMLDocumentNSDictionary*ns=[NSDictionarydictionaryWithObjectsAndKeys:@"http://www.freshbooks.com/api/",@"fb",nil];NSArray*projects=[docnodesForXPath:@"//fb:projects/fb:project"namespaces:nserror:nil];NSLog(@"%d",projects.count);
And finally, if you want to programatically register a namespace using GDataXml, then you would populate your NSDictionary by iterating through the namespaces found by GDataXMLElement:
Programmatically register a namespace with GDataXML
// doc is an instance of GDataXMLDocumentNSArray*namespaceURIs=[doc.rootElementnamespaces];
Just came across this great demo of using Core Animation in your iOS application. Its basically a demo application that allows you to try out each technique and then you can review the source. The project is on Github. You should also check out Bob McClune’s Blog, the creator of the demo.
When I do web development I always have some database manager open so that I can quickly review the data used by my application. So naturally with Core Data development, I want to be able to do the same thing. Since Core Data is working with a SQLite database, all you need is a SQLite database manager on your Mac. I have found two that I like: