Wednesday, July 27, 2011

Lesson 2

Basic data type of Objective-C are

char stores 'A','a','4' occupies in memory 1 Byte
Int stores 10,-234 occupies in memory 4 Bytes
float stores 1.34,-5.66 single precision values, occupies 4 bytes in memory
double stores 1.34,-9.56 double precision values, occupies 8 bytes in memory

Additional types based on Int

short stores 145,-3903 occupies 2 bytes in memory
long stores 343,-1000 occupies 4 bytes in memory
long long stores 1.99999 occupies 8 bytes in memory

other types are

Bool stores 0,1, false, true
void for null
id for object

With exception of both float and double data types, above mentioned all datatypes can be signed or unsigned. if we are not specifying either then compiler will assume signed

int is default datatype if you do not specify type. for example, if you are using signed or unsigned to mean a signed int or unsigned int respectively.

Note that

signed anInt =20 ;

is same as

int anInt =20;

even, you can write signed int anInt=20;

Size Range
1 byte signed: -128 to 127
unsigned: 0 to 255

2 bytes signed: -32768 to 32767
unsigned: 0 to 65535

4 bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295

8 bytes signed: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned: 0 to18,446,744,073,709,551,615

For floating point numbers, such as float and double.
For a float, the number of significant digits is 7 or 8, and for a double, the number of significant digits is 15 or 16.

Arithmetic Operators:
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo

Example of each operator

int a = 20;
int b = 10;
int c;

c = a + b; //Addition Ans: 30
c = a - b; //Subtraction Ans: 10
c = a * b; //Multiplication Ans: 200
c = a / b; //Division Ans: 2
c = a %b; //Modulo Ans: 0

String format specifiers:

char %c
Int %i,%d
signed int %i, %d
unsigned int %u
short %hi
signed short %hi
unsigned short %hu
long long %qi
signed long %qi
unsigned long %qu
float %f
double %F

Bitwise Operators

In the computer, your data is actually stored as ones and zeros which corresponds to something called a bit. In fact, the basic computations you do are in something called binary arithmetic.

Operator Usage
& Bitwise AND
| Bitwise OR (Bitwise inclusive OR)
^ Bitwise XOR(Bitwise exclusive OR)
~ Unary complement (bit inversion)
<< Shift Left
>> Shift Right

Compound Assignment Operators

+= Addition
-= Subtraction
*= Multiplication
/= Division
%= Modulo
&= Bitwise AND
|= Bitwise inclusive OR
^= Bitwise exclusive OR
<<= Shift Left
>>= Shift Right

Increment and Decrement Operators

++ incremented by 1
-- decremented by 1

for example,

int a = 10;
int b;

b = a++; means the value of b will be 10 and value of a will be 11 as ++ is in suffix mode


b = ++a; means the value of b will be 11 and value of a also will be 11 as ++ is in prefix mode

in prefix mode, first operator increment the value to variable and then assigned to variable

Comma operator

The comma operator (,) allows you to use two or more expressions where only one expression is expected.

int a;
int b;
a = ( b=3, b+2);

the comma operator, in the expression (b=3,b+2) will first evaluate b=3, resulting in the value of b becoming 3. the second operand is then evaluated, adding 2 to b, which results in the comma operator returning 5. Finally a is assigned that result, or 5. So, at the end, variable a will contain the value 5, whereas variable b will contain value 3.

Sunday, July 17, 2011

Lesson 1

Objective-C is an object oriented language which lies on top of the C language. Itʼs primary use to develop desktop application on Mac OS X machines and also on iPhone OS. It was originally the main language for NeXTSTEP OS and when Apple did tie up with NeXTSTEP then Apple introduced Mac OS X operating system for Apple machines and Objective-C became a primary development language.

Objective C is extenstion to ANSI C

So, we can say that

Objective C = ANSI C + OOPS

Most Object-Oriented development environments consist of several parts:

Object Oriented Programming language
Object library
Suite of development tools
Run time environment

if you have never worked with any object oriented programming language and this is your first OOPS language then i prefer you should first read "Object Oriented Programming Language with Objective-C"

As i mentioned earlier, Objective-C is primary language for iPhone development, however, here we are not focusing on iPhone development but concentrate on learning Objective-C first. I will definitely cover iPhone development lessons under different heading.

To learn Objective-C, you should have Mac machine with GCC compiler and development kit (XCode, Instruments, Interface Builder etc.) if it is not on your machine then you can download it from Apple's developer Website. It is totally free.

But if you are a big fan of Windows and planning to move to Mac application development then you need a compilers like Cygwin or MinGV and then install GNUStep from GNUStep website.

There are three components which are required on windows platform. there are listed below.

  • GNUStep MSYS System - MSYS/MinGW System - Contains all packages required to run GNUStep
  • GNUStep Core - GNUStep Code - GNUStep core libraries
  • GNUStep Devel - Developer Tool - it is a developer's kit, used to develop and compile programms

Chapter 1

Runtime System

Language requires not only a compiler but also runtime system to execute the compile code. The runtime system acts as kind of Operating system for the Objective-C language.
To learn more about functionalities offered by runtime, see "Objective-C Runtime Programming Guide"

Objects, Classes and Messaging


An object associates data with particular operations that can use or affect that data.

Data is instance Variable and operations are Methods

In many environment, people are considering them as Member variable and Member methods. it means Objects consists of Variables and Methods.

ID data type

In Objective-C, Object indentifiers are of a distinct data type: id. This type is the general type for any kind of object regardless of class.

id anObjects;

The Keyword nil is defined as a null object, an id with a value of 0. id, nil and other basic types of Objective-C are defined in a header file objc/objc.h.

Friday, July 15, 2011

Objective - C

If you want to learn Objective-C or you are stuck somewhere else on path of Objective C, ask me your question.

I will give you an answer with sample (if possible).