The document provides tutorials on various concepts in Objective-C and iOS application development including classes and objects, inheritance, encapsulation, properties, methods, conditionals, loops, and more. The tutorials include code examples to demonstrate each concept.
1. Tutorial - 1
Mobile application development platforms,
Android, Windows, iOS, Bada, Blackberry etc.
Android, iOS, and Windows application
development is high on demand and will remain
for coming few years.
Android/iOS and Windows application
development is also possible using non standard
tools.
Android: eclipse + android sdk or Android
Studio or Epselorator Studio (HTML5 + CSS3)
or Phone Gap or TheAppBuilder.com etc.
iOS: Xcode + MAC, Adobe, Appselorator
Studio (HTML5 + CSS3) or Phone Gap or The
App Builder etc.
Blackberry: Eclipse + Blackberry SDK
Windows: .NET
Tutorial – 2
#import <Foundation/Foundation.h>
2. int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
NSLog(@"Hello world");
[pool drain];
return 0;
}
}
Tutorial – 3
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
3. {
int n1=20;
int n2=40;
int sum=n1+n2;
NSLog(@"The sum of %i and %i
is %i",n1,n2,sum);
[pool drain];
return 0;
}
}
Tutorial – 4
@interface Person:NSObject
{
int age;
int weight;
}
-(void) print;
-(void) setAge : (int) a;
-(void) setWeight : (int) w;
4. @end
@implementation Person
-(void) print
{
NSLog (@"I am %i years old and weigh %i
pounds", age,weight);
}
-(void) setAge : (int) a
{
age=a;
}
-(void) setWeight : (int) w
{
weight=w;
}
@end
int main (int argc, const char argv[])
{
@NSAutoreleasepool
{
13. int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int i, usernumber;
NSLog (@"Enter the number and I will print
it");
scanf("%i",& usernumber);
for(int i=1; i<= usernumber ; i++)
NSLog(@"%i",i);
[pool drain];
return 0;
}
}
14. Tutorial – 12
Nested For Loop:-
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int usernumber;
for(int a=1; a<=3;a++)
{
NSLog(@"Enter a number");
scanf(“%i",&usernumber);
for(int b=1; b<= usernumber; b++)
NSLog(@"%i",usernumber);
}
[pool drain];
return 0;
}
}
15. Tutorial – 13
While Loop:-
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int num=1 ;
while (num<=6)
{
NSLog(@"%i",num);
num++;
}
[pool drain];
return 0;
}
}
16. Tutorial – 14
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int num=1 ;
int name;
scanf(“%i",&name);
while (num<=10)
{
NSLog(@"%i time %i= %i", num, name,
num*name);
num++;
}
[pool drain];
return 0;
}
}
Tutorial – 15
18. Tutorial – 16
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int n=1 ;
do
{
NSLog(@"%i squared is %i",n,n*n);
n++;
}
while (n<=10);
[pool drain];
return 0;
}
}
19. Tutorial – 17
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int n,r ;
NSLog(@"Enter a number");
scanf(“%i",&n);
r=n%2;
if(r==0)
NSLog(@"Your number is even");
else
NSLog(@"Your number is odd");
[pool drain];
return 0;
}
}
Tutorial – 18
Relational test and nested if
20. #import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int age,sex;
NSLog(@"Enter age");
scanf(“%i",&age);
NSLog(@"Enter sex (1:Boy 2:Girl)");
scanf(“%i",&sex);
if (age<18 || age >80)
NSLog(@"Go to another website");
else
{
if(sex==1)
NSLog(@"Welcome Man!!");
else
NSLog(@"Welcome Girl!!");
}
[pool drain];
return 0;
}
21. }
Tutorial – 19
Else if ladder
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int time;
NSLog(@"Enter the time");
scanf(“%i",&time);
if(time<11)
NSLog(@"Gud Morning!!");
else if(time<16)
NSLog(@"Gud Afternoon!!");
else if(time<24)
NSLog(@"Gud Night!!");
else
NSLog(@"What did u enter????");
[pool drain];
22. return 0;
}
}
Tutorial – 20
Switch
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int age=2;
switch(age)
{
case 1:
NSLog(@"They are cute");
break;
case 2:
NSLog(@"They are terrible");
break;
case 3:
23. NSLog(@"They are thirsty");
break;
case 4:
NSLog(@"They are 4");
break;
default:
NSLog(@"Enter valid number");
}
}
[pool drain];
return 0;
}
Tutorial – 21
Conditional Operator
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int a=2,b=3,c=0;
29. Person.m
#import"Person.h"
-(void) print
{
NSLog(@"I am %iyears old and weigh %i
pounds", age, weight);
}
-(void) dateAge : (int) a : (int) i
{
NSLog(@"You can date %i years old", (a/2+7)-
(i/10000));
}
Main.m
#import <Foundation/Foundation.h>
#import "Person.h"
int main (int argc, const char argv[])
{
@NSAutoreleasepool
{
Person *name=[[Person alloc]init];
53. Tutorial – 34
Enumerated Data Type
main.m
#import<Foundation/Foundation.h>
int main (int argc, const char argv[])
{
@NSAutoreleasepool
{
enum day {m,t,w,th,f};
enum day entry;
NSLog(@"Enter the number for getting the
day");
scanf(“%i",&entry);
switch(entry)
{
case m:
NSLog(@"Monday");
break;
case t:
NSLog(@"Tuesday");
break;
56. {
NSNumber *buckyint,*buckyfloat;
buckyint=[NSNumber numberWithInteger:100];
buckyfloat=[NSNumber numberWithFloat:100.123];
int x=[buckyint intValue];
float y=[buckyfloat floatValue];
NSLog(@"%i and %f",x,y);
if ([buckyint isEqualToNumber:buckyfloat]==YES)
NSLog(@"They are equal");
else
NSLog(@"They are not equal");
if ([buckyint
compare :buckyfloat]==NSOrderedAscending)
NSLog(@"First number is less");
else
NSLog(@"Second Number is less");
return 0;
}
}
Tutorial – 37
String Objects
main.m
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])