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
123
// 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
123
// 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:
Ok… some simple debugging showed it was actually registering a namespace, but what was it called? That lead me to some code just before the xmlRegisterNs call:
Now we’re getting somewhere. Next stop the definition of the kGDataXMLXPathDefaultNamespacePrefix constant:
kGDataXMLXPathDefaultNamespacePrefix Definition
123
// 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
123
// 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
1234
// 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
12
// 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.
If your looking to build a community around your iPhone or iPad application, then you should check out Socialize on Github. The Socialize website explains all the features.
You’ve probably seen those iPhone applications that refresh the content when you pull down on the TableView. I have found three libraries that you can use to implement this in your own apps:
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:
This will help you quickly drill into the various application directories. You’ll find the SQLite database inside the Documents folder of your application inside the iPhone Simulator directory.
If you would like to output the SQL being generated by Core Data during iOS development you need to add an entry to the Arguments Passed On Launch for your app. Its as easy as:
Go to Product -> Edit Scheme
Choose Run YourAppName.app on the left panel
Add -com.apple.CoreData.SQLDebug 1 to the Arguments Passed On Launch panel