Sunday, July 25, 2010

How to show alert for iOS?

This is how you can show an alert box in iPhone or iPad app.


In your code include the following:

UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"Confirm"];
[alert setMessage:@"Buy This?"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
[alert show];
[alert release];

Then implement this in the delegate, in this case, the controller which calls UIAlertView.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// Yes, do something
NSLog(@"Yes!");
}
else if (buttonIndex == 1)
{
// No
NSLog(@"No!");
}
}

how to list files in iOS

This is how you can list files in your iPhone apps.

NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory];
for (NSString *s in fileList){
NSLog(s);
}

How to test if file exist in iPhone iOS

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:somePath];

Friday, July 23, 2010

How to get Application Name with code

Below is how you can get the name of your application with code.

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]

Wednesday, July 21, 2010

How to enable SQL debugging for Core Data in XCode

Right click on the project executable and click “Get Info.” Navigate to the Arguments tab and add the following argument: “-com.apple.CoreData.SQLDebug 1″.

When the project is running, you should see the sql used in the console.

Thanks to http://www.raywenderlich.com/934/core-data-tutorial-getting-started