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>
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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>
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
{
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;
@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
{
Person *ankit;
ankit=[Person alloc];
ankit=[Person init];
[ankit setAge:20];
[ankit setWeight:100];
[ankit print];
return 0;
}
}
Replacement in previous tutorial
Tutorial: 5
Person *name= [[Person alloc]init];
Person *sandy=[[Person alloc]init];
[sandy setAge: 21];
[sandy setWeight:450];
[sandy print];
[sandy release];
[pool drain];
return 0;
Tutorial – 6
Encapsulation
@interface Person:NSObject
{
int age,
int weight,
}
-(void) print;
-(void) setAge : (int) a;
-(void) setWeight : (int) w;
-(int) age;
-(int) weight;
@end
@implementation Person
-(void) print
{
NSLog (@"I am %i years old and weigh %i
pounds", age,weight);
}
-(int) setAge : (int) a
{
age=a;
}
-(int) setWeight : (int) w
{
weight=w;
}
-(int) age
{
return age;
}
-(int) weight
{
return weight;
}
@end
int main(int argc, const char * argv[])
{
@NSAutoreleaspool
{
Person *name= [[Person alloc]init];
[name setAge:25];
[name setWeight: 200];
NSLog(@"Name is %i and weighs %i",
[name age],[name
weight]);
[name release];
[pool drain];
return 0;
}
}
Tutorial – 7
Data Types
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int i=20;
float f=31.37;
double d= 9/32;
char c = ‘a’;
NSLog (@"%i",i);
NSLog (@"%f",f);
NSLog (@"%e",d);
NSLog (@"%c",c);
[pool drain];
return 0;
}
}
Tutorial – 8
TypeCasting
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int i1, i2=15, i3=10;
float f1=20.86, f2;
i1=f1;
NSLog (@"%i",i1);
f2=i2/i3;
NSLog (@"%f",f2);
f2=f1/i3;
NSLog (@"%f",f2);
[pool drain];
return 0;
}
}
Tutorial – 9
Type Casting (Explicite)
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int i1, i2=15, i3=10;
float f1=20.86, f2;
f2=(float)i3/8;
NSLog (@"%f",f2);
int name = (int)22.77;
NSLog (@"%i",name);
name = name + 5; // name += 5;
NSLog(@"%i", name);
(Shorthand)
name+=5;
NSLog(@"%i", name);
[pool drain];
return 0;
}
}
LOOPS
Tutorial – 10
For Loop:-
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
for(int i=1;i<=10;i++)
NSLog(@"%i", i);
[pool drain];
return 0;
}
}
Tutorial – 11
#import <Foundation/Foundation.h>
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;
}
}
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;
}
}
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;
}
}
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
Do-While Loop:-
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
@NSAutoreleasepool
{
int n=1 ;
do
{
NSLog(@"%i",n);
n++;
}
while (n<=5);
[pool drain];
return 0;
}
}
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;
}
}
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
#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;
}
}
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];
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:
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;
a==b ? NSLog(@"They are equal") :
NSLog(@"They are different");
c ? NSLog(@"True") : NSLog
(@"False");
}
[pool drain];
return 0;
}
Tutorial – 22
MVC Architecture
Person.h
@interface Person:NSObject
{
int age,weight;
}
-(void) print;
-(void) setAge : (int) a;
-(void) setWeight : (int) w;//void setWeight(int
w);
@end
Person.m
#import “Person.h"
@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
Main.m
#import<Foundation/Foundation.h>
#import “Person.h"
int main (int argc, const char argv[])
{
@NSAutoreleasepool
{
Person *name=[[Person alloc]init];
//Person ob = new Person();
[name setAge:20];
[name setWeight:100];
[name print];
[name release];
[pool drain];
return 0;
}
}
Tutorial – 23
Automatic Setter& Getter
Person.h
@interface Person:NSObject
{
int age,weight;
}
@property int age,weight;
-(void) print;
@end
Person.m
#import "Person.h"
@implementation Person
@synthesis age,weight;
-(void) print
{
NSLog(@"I am %iyears old and weigh %i
pounds", age, weight);
}
@end
Main.m
#import<Foundation/Foundation.h>
#import “Person.h"
int main (int argc, const char argv[])
{
@NSAutoreleasepool
{
Person *name=[[Person alloc]init];
name.age = 20;
name.weight = 100;
[name print];
[name release];
[pool drain];
return 0;
}
}
Tutorial – 24
Multiple Arguments
Person.h
@interface Person:NSObject
{
int age,weight;
}
@property int age,weight;
@end
-(void) print;
-(void) dateAge : (int) a : (int) i;
Person.m
#import"Person.h"
-(void) print
{
NSLog(@"I am %iyears old and weigh %i pounds", age, weight);
{ 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[])
{ @autoreleasepool { NSString *s=@"dont do this"; NSString *tester; printf("%@",s); NSLog(@"Length is %i",[s length]); tester=[NSString stringWithString:s]; NSLog(@"Copied string is %@",tester); tester=[s uppercaseString]; NSLog(@"%@", tester); } return 0; }