Wednesday, November 23, 2011

NSCountedSet (grouping array objects with their total number of counts)

This class gives the count of an object present in an array.

For example: If we have an array named myArray with objects: (AA,HH,TT,SS,AA,KK,TT,TT,XX,HH,HH,HH,SS,SS)

Then to get total no of count of every object only write this code:


 NSCountedSet * set = [[NSCountedSet alloc] initWithArray: myArray];
        for (id obj in set)
        {
            NSLog(@"%d - %@", [set countForObject:obj], obj);
         }

Now you can use this [set countForObject:obj] and obj according to your requirement. 

For example it you want to display this in a table with non-repeated objects and with count you can assign above value in a dictionary like this: 

NSMutableDictionary *dirCount = [[NSMutableDictionary alloc]init];
NSCountedSet * set = [[NSCountedSet alloc] initWithArray:arrForTypeGroup];

        for (id obj in set)
        {
            NSLog(@"%d - %@", [set countForObject:obj], obj);
            [dirCount setObject:[NSNumber numberWithInt:[set countForObject:obj]] forKey:obj];
        }


 NSLog(@"Output: %@", dirCount);

Now use this dictionary to display in table.

Happy Coding :)

Sunday, November 13, 2011

PhoneGap


PhoneGap lets developers use web technologies to develop an iPhone app. Apple has a web browser object developers can use to display HTML content. Usually developers use it to display HTML from a remote web server. What PhoneGap does is let developers create their user interface using HTML in the web browser object instead of the built-in user interface objects (buttons, lists, text fields, etc).
Normally, this would be very limiting, since web browsers can't access most of the services a smartphone provides - what PhoneGap does is "bridge the gap" (hence the name) between the smartphone and the web browser by exposing smartphone services using JavaScript.
For developers that don't have experience with a smartphone's native development tools, using PhoneGap lets them leverage their knowledge of HTML and JavaScript to make an app. PhoneGap also makes it easier to support multiple smartphone platforms because much of the HTML and JavaScript can be reused between platforms which have this web browser object. (iPhone, Android, the newest Blackberry phones, and Palm webOS phones).
To clarify further, the HTML and JavaScript you put into a the web browser object in a PhoneGap app isn't served by a web server over the Internet - it is embedded into the app. That doesn't mean your app is forever limited to what is put into it when it ships - just as they would otherwise, the developer integrates the PhoneGap screens with your remote data sources (typically via JSON web services) - in this case the PhoneGap screens are like templates. If changes to the template are needed, the developer updates them and submits an updated app to the App Store. This is no different than for apps that don't use PhoneGap - any changes to apps must be re-submitted to the App Store before they can appear on people's phones.