Tuesday, March 16, 2010

Count No of occurrences of a String or a character

Hi Friends,

I was in a search of a function that would give the number of occurrences of a character or a string in another string and finally I landed in the following solution. If you have any other way to achieve it, please share it.

+ (NSInteger)occurrencesOf:(NSString *)str InString:(NSString *)mainString
{

return [[mainString componentsSeparatedByString:str] count];

}

Thank you.

Friday, March 12, 2010

iPhone OS 4.0 Multitasking

Hi Friends,
This is a good news for iPhone and future iPad users, if it is true as reported in AppleInsider. And as reported this move would silence the critics who always take a dig at apple for not providing the Multitasking. And the main thing to watch out is how is going to achieve it without compromising on battery life.

Lets wait and see whats happening!!

Thursday, March 4, 2010

Rename project File and Target Name in XCode

Hi Friends,

This post is going to help you to change the name of your Project in XCode. And follow the steps given below to achieve the same.

1. Make a copy of your project Folder and delete the build folder if there is one.
2. Rename it to the name you wish to have.
3. Change the name of the .xcodeproj file to the name you wish to have.
4. Change the name of the .pch file.

Now it seems to be fine and when you run you will be blocked by the following error:
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

So lets get to the fifth step.
5. Go to the Targets. Right click on your Target Name and click Get Info.
6. Now go to the Build tab and find the GCC_PREFIX_HEADER in the User-Defined section and you will find the name of the .pch file that you have just renamed and voila.

For renaming the Target, just change the "Bundle display name" in your <project-Name>-info.plist file. And your done...

Monday, March 1, 2010

Palm WebOS- Web Service and Persistent Storage

Hi Friends,

This article will take you through the ways of handling Web Service and Persistent Storage in Palm Web OS.

First let us look at Web Service.

Web Service

1. We can access webservice using two means.
a. Prototype Javascript Framework (Ajax.Request)
b. Native javascript (XMLHTTPRequest)
2. Exchange data can be of any form (JSON, XML, or any of your own format)
3. Currently only asynchronous operations are supported using XMLHTTPRequest, done to preserve UI responsiveness. (I have not checked with the Ajax.Request. If someone has verified it, please share them)
4.Use Prototype Javascript Framework if you don't wish to control every operation yourself and the framework will take care of everything.
5. use Native Javascript if you wanted more control over your code.

Processing JSON:


1. Two ways:
a. eval()- best to avoid, only if source is trusted.
b. JSON parser- faster, never allow malicious script to get executed.

Processing XML:

1. use either DOM or a SAX parser.

Now lets turn towards, Persistent Storage:

Memory is partitioned as three segments:

1. root- for the OS and apps that come by default like calendar, Browser.
2. var -meant for third party Applications, that we are wiling to develop.
3. Media-media partition are visible on the USB volume( Available in your computer, when you plug-in your Palm based phone- pre or pixi).

Three ways to store data:

1. Cookie
2. Depot
3. HTML5

All three forms of data are tied to an application. So, they will be deleted, if you delete your application from the device.

Cookie:

1. Data stored as a key-value pair.
2. It has nothing to do with the Web browser cookie, other than storing data.
3. Maximum of 4KB of data.
4. Can be used to store preferences, simple settings.

Depot:

1. Can store up to 1 MB of data.
2. Size can be extended by using a keyword ext,while creating database.
3. Data stored as Key-value pair.
4. Normal way of creating DB:
var db = new Mojo.Depot({name:”demo”}, onSuccess, onFailure);
5. For extended storage:
var db = new Mojo.Depot({name:”ext:demo”}, onSuccess, onFailure);

HTML 5 database

1. It is a structured database, unlike the first two.
2. Normal way of creating the DB:
this. db = openDatabase("myDB", 1, "My DB", 10000);
3. To store data in Media partition, use
this. db = openDatabase("ext:myDB", 1, "My DB", 10000);


Depot and HTML5 DB operations are asynchronous, unlike the Cookies.

And thats all for this article. Thank you.