• Skip to main content
  • Skip to primary sidebar

Ravi Shankar

Tweaking Apps

  • About
  • Portfolio
  • Privacy Policy

Archives for January 2012

How to set Keynote as default application for PPT file

January 27, 2012 By Ravi Shankar Leave a Comment

Mac OS X Lion is pre-installed with OpenOffice software and this is set as the default application for opening any PowerPoint presentation file. Mentioned below are the steps required to set Apple Keynote as the default application for opening PPT file.

  • Launch Finder application on Mac and locate the PPT file.
  • Right click on the PPT file, navigate to Open With and Select Other option.

201201271605.jpg  

  • This would display the following Choose Application window.

201201271607.jpg

  • Scroll down the application list and pick Keynote. Then mark the check box with label as “Always Open With” and click the Open button.

201201271609.jpg

  • This would launch the Keynote application with the selected PowerPoint Presentation file.

Now when ever a PPT file is opened, it will be automatically opened in Apple Keynote.

Filed Under: Apple, Keynote, PowerPoint 2010 Tagged With: Apple, Default, Keynote, Mac OS X Lion, Powerpoint 2010, presentation

Dissecting Objective-C program

January 14, 2012 By Ravi Shankar Leave a Comment

Fotolia_29238788_XS.jpg

We have already seen couple of examples in Objective-C like writing your first program in Objective-C and adding Objective-C classes. Now let us try and analyze the code to learn basic coding on Objective-C program.

Adding Comments

The very basic thing to learn is any programming language is “how to add comments”. In Objective-C you can add comments by adding two consecutive slashes “//” before the text entries. And if you want to add block of comments (more than one line) then you start with /* and end the comment with */

Including Header files

In Objective-C, users can include header files by adding “#import <header filename>”. This would include functions and classes from the header files in to the current program. The examples that has been discussed includes “Foundation” and “Calci” header files.

#import <Foundation/Foundation.h>

#import “Calci.h”

main keyword

int main (int argc, const char * argv[])

“main” is the keyword that marks the beginning line for execution of the program.

Reserving memory

  @autoreleasepool {

The execution code is provided within autoreleasepool and this allocates memory for the program. Now you do not have to explicitly drain the pool, the latest release will automatically drain the allocated memory.

Printing Message

 

  NSLog(@”My First Objective C Program using Xcode!”);

 

NSLog routine is used for printing text messages to the console. The text that needs to be printed is preceded with “@” character. And if you want to print value from a variable then you can use “%i” along with text.

 

NSLog(@”Addition of two numbers %i”, [calculator addition]);

 

Method definition

 

In Objective-C, you can define methods as shown below

 

-(void) setNumber1:(int) n1

-(int) addition

  • “-” refers to the access specifier.
  • void and int specifies the return type for the method.
  • setNumber1 and addition refers to the method name.
  • (int) n1 specifies the type of argument and argument that will be passed to the method.
  • return number1+number2; – “return” keyword is used returning the value from the method.

Filed Under: Apple, Develop, ios Tagged With: Apple, Objective C, Program

Basic tutorial – Adding Objective-C Class using Xcode

January 13, 2012 By Ravi Shankar 1 Comment

Let us see how to add a class in Objective-C by looking at an example that provides basic functionality of adding two numbers. In this example we will be using Xcode for development similar to the earlier post on first program in Objective C using Xcode.

This program is going to have to three main section.

  • Defining Interfaces.
  • Implementing Class methods.
  • Using Objective C class in the program.

Xcode users can add a new class to an existing project by clicking File -> New

201201131923.jpg

This would display the following “Choose a template for your new file” window. Now select Objective-C class from the templates and click Next button.

201201131930.jpg

Then provide a name for the Class some thing like Calci. Also select the Subclass for the class as NSObject and click Next button.

201201131931.jpg

Now this would add two files with extension .h and .m, “Calci.h” and “Calci.m”.

Defining Interfaces

You can define the interface required for adding two numbers in header file (Calci.h). When you add the class file using Xcode, it will be pre-populated with the following code in “Cacl.h” header file.

//

// Calci.h

// Exercise2

//

// Created by Ravi Shankar on 13/01/12.

// Copyright (c) 2012 __MyCompanyName__. All rights reserved.

//

#import <Foundation/Foundation.h>

@interface Calci : NSObject

Write two interfaces for setting the two numbers and another interface for adding the two numbers.

#import <Foundation/Foundation.h>

@interface Calci : NSObject

{

int number1;

int number2;

}

-(void) setNumber1: (int) n1;

-(void) setNumber2: (int) n2;

-(int) addition;

@end

Implementing Methods

After defining the interfaces, implement those interfaces in .m file (Calci.m). When a new class is added, Xcode will pre-populate the .m file with the following code.

//

// Calci.m

// Exercise2

//

// Created by Ravi Shankar on 13/01/12.

// Copyright (c) 2012 __MyCompanyName__. All rights reserved.

//

#import “Calci.h”

@implementation Calci

Now add the following piece of code to add the functionality for settings the two numbers and a method that adds these numbers.

#import “Calci.h”

@implementation Calci

-(void) setNumber1:(int) n1

{

number1 = n1;

}

-(void) setNumber2:(int) n2

{

number2 = n2;

}

-(int) addition

{

return number1+number2;

}

@end

Using Objective C class in the program

After defining and implementing the interfaces in the .h and .m file, now it is time to use the functionality in the program.

  @autoreleasepool {

  

Calci *calculator;

calculator = [Calci alloc];

calculator = [calculator init];

[calculator setNumber1: 35];

[calculator setNumber2: 65];

  

// insert code here…

NSLog(@”Addition of two numbers %i”, [calculator addition]);

  

}

The above code creates an instance of the “Calci” class, then passes the two numbers that needs to be added. Finally [calculator addition] does the addition and the result is printed using NSLog routine.

Filed Under: Apple, ios Tagged With: Apple, Classes, Objective C, Xcode

My fiirst program in Objective C using Xcode

January 11, 2012 By Ravi Shankar Leave a Comment

This tutorial is about writing a basic and simple program in Objective C using Xcode. Let us see an example program that prints “My First Program” in the Console Window.

Xcode new project window

Click the File menu on Xcode, then navigate to New -> New Project. This would display the following Choose a template window. Now select Application under Mac OS X then the Command Line Tool option.

Xcode Command Line Tool

In the Choose options for your new project, enter the name of Product Name and select the Type as Foundation and leave the rest of the option as it is. Click Next to continue with the project creation.

Xcode Choose Project Options

Now specify the location where you want to create the project folder and click Next to continue with the setup.

Xcode Project Creation Folder

This would create a new project window as shown below.

Xcode Project Window

Navigate to Project Navigator and edit main.m file. The Xcode would have already pre-populated code as shown below

//

// main.m

// Exercise1

//

// Created by Ravi Shankar on 11/01/12.

// Copyright (c) 2012 __MyCompanyName__. All rights reserved.

//

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])

{

@autoreleasepool {

// insert code here…

NSLog(@”Hello, World!”);

}

return 0;

}

Change the “Hello World” text to “My First Objective C Program using Xcode” and save the changes (Command + S).

@autoreleasepool {

// insert code here…

NSLog(@”My First Objective C Program using Xcode!”);

}

You can Run the project in Xcode by clicking Product menu and select Run from the menu list.

Xcode Project Build

You can Run Once the build is complete and successful, the output window in the bottom of Xcode will print the message as “My First Objective C Program using Xcode”.

Xcode Console Output Window

Filed Under: Apple, Develop, ios Tagged With: Apple, Objective C, Program, Xcode

Primary Sidebar

Recent Posts

  • We have blocked all requests from this device – Firebase Phone Authentication
  • iPhone is not available error message in Xcode
  • Clear CocoaPods cache, re-download and reinstall all pods
  • PDFKit – View, Annotate PDF file in Swift
  • Tab Bar Controller with WebView

Archives

  • September 2020
  • April 2020
  • December 2019
  • November 2019
  • October 2019
  • February 2019
  • October 2017
  • June 2017
  • May 2017
  • March 2017
  • September 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • April 2011
  • March 2011
  • January 2011
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • July 2009
  • March 2008

Copyright 2020 © rshankar.com