ios,objective tutorial

64
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>

Upload: bhavik-patel

Post on 24-Jan-2018

103 views

Category:

Engineering


0 download

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);

}

-(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];

name.age = 12;

name.weight = 120;

[name print];

[name dateAge : 30:300000];

[name release];

[pool drain];

return 0;

}

}

Tutorial – 25

Inheritance

Main.m

#import <Foundation/Foundation.h>

@interface Lesley: NSObject

{

int a;

}

-(void) meth;

@end

@implementation Lesley

-(void) meth

{

a=50;

}

@end

@interface Son: Lesley

-(void) printThing;

@end

@implementation Son

-(void) printThing

{

NSLog(@"%i",a);

}

@end

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

{

@NSAotoreleasepool

{

son *s=[[son alloc]init];

[s meth];

[s printThing];

[s release];

[pool drain];

return 0;

}

}

Tutorial – 26

Rectangle.h

@interface Rectangle:NSObject

{

int width, height;

}

@property int width,height;

-(int) area;

-(int) parameter;

-(void) setWH : (int) w : (int) h;

@end

Rectangle.m

#import “Rectangle.h"

@implementation Rectangle

@synthesize width,height;

-(void) setWH : (int)w : (int)h

{

width=w;

height=h;

}

-(int) area

{

return width*height;

}

-(int) parameter

{

return (width+height)*2;

}

@end

Main.m

#import <Foundation/Foundation.h>

#import "Rectangle.h"

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

{

@NSAutoreleasepool

{

Rectangle *r=[[Rectangle alloc]init];

[r setWH:6:8];

NSLog(@"Rectangle is %i

by %i",r.width,r.height);

NSLog(@"Area is %i, Parameter is %i",[r

area],[r parameter]);

[r release];

return 0;

}

}

Tutorial – 27

Square.h

#import “Rectangle.h"

@interface Square:Rectangle

-(void) setSide: (int)s;

-(int) side;

@end

Square.m

#import “square.h"

@implementation Square: Rectangle

-(void) setSide : (int)s

{

[self setWH :s:s];

}

-(int) side

{

return width;

}

@end

Main.m

#import <Foundation/Foundation.h>

#import “Square.h"

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

{

@NSAutoreleasepool

{

Square *s= [[Square alloc]init];

[s setSide:6];

NSLog(@"One side is %i", [s side]);

NSLog(@"Area is %i and perameter

is %i",[s area],[s parameter]);

[s release];

[pool drain];

return 0;

}

}

Tutorial – 28

Mom.h

@interface Mom:NSObject

{

int num1;

}

-(void) setNum1;

@end

Mom.m

#import “Mom.h"

@implementation Mom

-(void) setNum1

{

num1=70;

}

@end

Son.h

#import “Mom.h"

@interface Son:Mom

-(void) setNum1;

-(void)printNumber;

@end

Son.m

#import “Son.h"

@implementation Son

-(void)setNum1

{

num1= 14;

}

-(void)printNumber

{

NSLog(@"The number is %i",num1);

}

@end

Main.m

#import<Foundation/Foundation.h>

#import “Son.h"

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

{

@NSAutoreleasepool

{

Son *s=[[Son alloc]init];

[s setNum];

[s printNumber];

[s release];

[pool drain];

return 0;

}

}

Tutorial – 29

numz.h

@interface numz:NSObject

{

int num1,num2,ans;

}

-(void) setNumbers : (int) a : (int) b;

-(void) add;

-(void) print;

Numz.m

@implementation Numz

-(void) setNumbers: (int) a: (int) b

{

num1 = a;

num2= b;

}

-(void) add

{

ans=num1+num2;

}

-(void) print

{

NSLog(@"I am from numz class, %i",ans);

}

@end

charz.h

@interface charz:NSObject

{

char c1;

char c2;

}

-(void) setCharz;

-(void)add;

-(void)print;

@end

charz.m

@implementation charz

-(void) setCharz

{

c1=’B’;

c2=’W’;

}

-(void) add

{

NSLog(@"%c %c",c1,c2);

}

-(void)print

{

NSLog(@"I am from the chaz class");

}

Main.m

#import<Foundation/Foundation.h>

#import “numz.h"

#import “charz.h"

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

{

@NSAutoreleasepool

{

numz *n =[[numz alloc]init];

charz *c =[[charz alloc]init];

[n setNumbers :8:10];

[n add];

[n print];

[c setCharz];

[c add];

[c print];

[n release];

[c release];

[pool drain];

return 0;

}

}

Tutorial – 30

numz.h

@interface numz:NSObject

{

int num1,num2,ans;

}

-(void) setNumbers : (int) a : (int) b;

-(void) add;

-(void) print;

Numz.m

@implementation Numz

-(void) setNumbers: (int) a: (int) b

{

num1 = a;

num2= b;

}

-(void) add

{

ans=num1+num2;

}

-(void) print

{

NSLog(@"I am grom numz class, %i",ans);

}

@end

charz.h

@interface charz:NSObject

{

char c1;

char c2;

}

-(void) setCharz;

-(void)add;

-(void)print;

@end

charz.m

@implementation charz

-(void) setCharz

{

c1=’B’;

c2=’W’;

}

-(void) add

{

NSLog(@"%c %c",c1,c2);

}

-(void)print

{

NSLog(@"I am from the chaz class");

}

Main.m

#import<Foundation/Foundation.h>

#import “numz.h"

#import “charz.h"

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

{

@NSAutoreleasepool

{

numz *n =[[numz alloc]init];

charz *c =[[charz alloc]init];

[n setNumbers :8:10];

[n add];

[n print];

[c setCharz];

[c add];

[c print];

[n release];

[c release];

[pool drain];

return 0;

}

}

Tutorial – 31

numz.h

@interface numz:NSObject

{

int num1,num2,ans;

}

-(void) setNumbers : (int) a : (int) b;

-(void) add;

-(void) print;

Numz.m

@implementation Numz

-(void) setNumbers: (int) a: (int) b

{

num1 = a;

num2= b;

}

-(void) add

{

ans=num1+num2;

}

-(void) print

{

NSLog(@"I am grom numz class, %i",ans);

}

@end

charz.h

@interface chaez:NSObject

{

char c1;

char c2;

}

-(void) setCharz;

-(void)add;

-(void)print;

@end

charz.m

@implementation charz

-(void) setCharz

{

c1=’B’;

c2=’W’;

}

-(void) add

{

NSLog(@"%c %c",c1,c2);

}

-(void)print

{

NSLog(@"I am from the chaz class");

}

Main.m

#import<Foundation/Foundation.h>

#import “numz.h"

#import “charz.h"

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

{

@NSAutoreleasepool

{

id tuna;

numz *n =[[numz alloc]init];

charz *c=[[charz alloc]init];

tuna=n;

[tuna print];

tuna=c;

[tuna print];

[pool drain];

return 0;

}

}

Tutorial – 32

Exception Handling

numz.h

@interface numz:NSObject

{

int num1,num2,ans;

}

-(void) setNumbers : (int) a : (int) b;

-(void) add;

-(void) print;

Numz.m

@implementation Numz

-(void) setNumbers: (int) a: (int) b

{

num1 = a;

num2= b;

}

-(void) add

{

ans=num1+num2;

}

-(void) print

{

NSLog(@"I am grom numz class, %i",ans);

}

@end

Main.m

#import<Foundation/Foundation.h>

#import “numz.h"

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

{

@NSAutoreleasepool

{

numz *n =[[numz alloc]init];

@try

{

[n this_is_gonna_get_error];

}

@ catch (NSException *e)

{

NSLog(@"you got an error in your

program");

}

NSLog(@"this is the code after error");

[pool drain];

return 0;

}

}

Tutorial – 33

Extern keyword

tuna.h

@interface tuna:NSObject

-(void) changeVar;

tuna.m

@implementation tuna

-(void) changeVar

{

extern int gdrunk;

gdrunk=13;

}

Main.m

#import<Foundation/Foundation.h>

#import “tuna.h"

int gdrunk=21; //Global Variable

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

{

@NSAutoreleasepool

{

tuna *f =[[tuna alloc]init];

[f changeVar];

NSLog(@"%i",gdrunk);

[f release];

[pool drain];

return 0;

}

}

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;

case w:

NSLog(@"Wednesday");

break;

case th:

NSLog(@"Thursday");

break;

case f:

NSLog(@"Friday");

break;

default:

NSLog(@"Enter the number within the range");

break;

}

}

}

Tutorial – 35

Define Statement

crap.m

#define BACON 23

#define TOAST 44

main.m

#import <Foundation/Foundation.h>

#import “crap.h"

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

{

@NSAutoreleasepool

{

int x= TOAST + BACON;

NSLog(@"%i",x);

[pool drain];

}

}

Tutorial – 36

Frameworks

NSNumber

main.m

#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool

{ 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; }

Tutorial – 38

Substring

main.m

#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool

{ NSString *s = @"Cats dont like bananas"; NSString *d = @"Don’t feed grapes to dogs"; NSString *tester; tester = [d substringToIndex:10]; NSLog(@"First 10 characters are %@",tester); tester = [d substringFromIndex:10]; NSLog(@"From 10 till the end %@",tester); //tester = [d substringWithRange (5,11)]; //NSLog(@" %@",tester); NSRange range = [d rangeOfString:@"grapes"]; NSLog(@"Location is %i and length is %i", range.location,range.length); } return 0; }

Tutorial – 39

Mutable String

main.m

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) { @autoreleasepool { NSString *dog = @"Hot dog "; NSMutableString *mute; mute = [NSMutableString stringWithString:dog]; NSLog(@"%@",mute); [mute insertString: @"sauce" atIndex:8]; NSLog(@"%@",mute); [mute deleteCharactersInRange: NSMakeRange(4,3)]; NSLog(@"%@",mute); } return 0; }

Tutorial – 40

Mutable String

main.m

#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSString *dog = @"Hot dog? I thought you said pumpkin"; NSMutableString *mute; mute = [NSMutableString stringWithString:dog];

NSLog(@"%@",mute); [mute setString: @"I am a new string!"]; NSLog(@"%@",mute); [mute replaceCharactersInRange : NSMakeRange(11,7) withString :@"mother!"]; NSLog(@"%@",mute); NSString *old=@"mother"; NSString *new=@"baby seal"; NSRange therange = [mute rangeOfString:old]; [mute replaceCharactersInRange:therange withString:new]; NSLog(@"%@",mute); } return 0; }

Tutorial – 41

Array

main.m

#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool {

NSArray * food =[NSArray arrayWithObjects:@"apple",@"orang",@"mango",@"banana", nil]; for(int i=0;i<4;i++) { NSLog(@"item at index %i is %@",i,[food objectAtIndex:i]); } } return 0; }

Tutorial – 42

Mutable Array

main.m

#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSMutableArray *changeme = [NSMutableArray arrayWithCapacity:25]; [changeme addObject: [NSNumber numberWithInteger:2]]; for(int i=0;i<=100;i++) {

[changeme addObject:[NSNumber numberWithInteger:i]]; } for(int x=0;x<[changeme count];x++) { NSLog(@"%d=%li",x,(long)[[changeme objectAtIndex:x]integerValue]); } return 0; } }

Tutorial – 43

Dictionaries

main.m

#import <Foundation/Foundation.h>

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

{

@NSAutoreleasepool

{

NSMutableDictionary *mydic =

[NSMutableDictionary dictionary];

[mydic setObject:@"When you spray youself

with free breez" forKey:@"freebreez shower"];

[mydic setObject:@"gamer who lacks

experience" forKey:@"Noob"];

[mydic setObject:@"worst food on the planet" forKey:@"sushi"];

NSLog(@"%@",[mydic

objectForKey:@"sushi"]);

}

}

Tutorial – 44

Files

main.m

#import <Foundation/Foundation.h>

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

{

@NSAutoreleasepool

{

NSString *testerfile = @"testerfile";

NSFileManager *manager;

manager=[NSFileManager defaultManager];

//Creates a default file manager

if([manager fileExistsAtPath : testerfile]==NO)

{

NSLog(@"File does not exists");

return 1;

}

// Copy of a file

if ([manager copyItemAtPath : testerfile

toPath:@"newfile" error : NULL]== NO)

{

NSLog(@"Cannot copy the file");

return 2;

}

//Rename the copy file

if ([manager moveItemAtPath:@"newfile"

toPath:@"newfile2" error:NULL]==NO)

{

NSLog(@"Cannot rename it");

return 3;

}