• Skip to main content
  • Skip to primary sidebar

Ravi Shankar

Tweaking Apps

  • Swift
  • Tech Tips

Xcode

How to set Organization name for Xcode Project

February 3, 2012 By Ravi Shankar Leave a Comment

When ever a new project is created in Xcode, the projects files like header and implementation files will have auto generated comment section at the top of the file. This comment section will have information such as file name, Project name, Author and Organization name.

//

// ViewController.h

// Welcome

//

// Created by Ravi Shankar on 02/02/12.

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

//

If you have not set the organization name then the default value substituted will be _MyCompanyName_. You can set the Organization name by the following ways.

  • Setting Organization name under File Inspector
  • Updating Company name for the user in Mac Address book

File Inspector

Select the Project in the Project Navigator, then navigate to Utilities section and click the File Inspector icon. Now navigate to Project Document section and enter the company name in field with caption as Organization.

201202031600.jpg

Now if you add any new file to this project then the auto generated comment will have the company name as “rshankar.com”.

Address Book

If you want to retain this organization name for all the future projects then update the company name for the user in Mac Address Book. Launch Address Book, then select the user and update the company name as shown below.

201202031613.jpg

Now when ever a new project or new file is added in Xcode, the Organization name will be set the value provided for company name in address book.

//

// ViewController.h

// OrganizationName

//

// Created by Ravi Shankar on 03/02/12.

// Copyright (c) 2012 rshankar.com. All rights reserved.

//

Please note that any files created before this change will not get affected and you will have to manually update company name.

Filed Under: Xcode Tagged With: Apple, Organization, Xcode

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

  1. Pages:
  2. «
  3. 1
  4. 2
  5. 3
  6. 4
  7. 5
  8. 6
« Previous Page

Primary Sidebar

TwitterLinkedin

Recent Posts

  • How to block keywords in Jio broadband
  • How to disable opening an app automatically at login in Mac
  • How to set preferred Wifi network on Mac
  • Attribute Unavailable: Estimated section warning before iOS 11.0
  • How to recover Firefox password from Time Machine backup

Pages

  • About
  • Privacy Policy
  • Terms and Conditions

Copyright 2022 © rshankar.com

Terms and Conditions - Privacy Policy