Monday, 18 February 2013


HI THIS TOUTORIAL WILL HELP FULL FOR STARTUP IN IOS CREATED BY NAVEENRAJU



IOS BASICS EXPLINATIONS BY NAVEENRAJU


OBJECTIVE C

  • Introduction to Objective-c programming
  • Primitive Data Types and Operators
  • Flow Control Statements
  • Arrays and Structures
  • Classes, Objects, and Messaging
  • Memory Management and Properties
  • Inheritance, Polymorphism
  • Protocols and Categories
  • Introduction to Foundation Framework Classes
  • File Handling
  • Property Lists, NSCopy, and Archiving
  • Selectors and Targets
  • Dynamic Typing and Dynamic Binding






Arrays and Structures





Arrays 

In Single Variabule we can hold many diff values
They are two types of Array
1}ImmutabuleArray(NSArray)
2)MutableArray(NSMutabuleArray)


















code for Array:

//
//  ViewController.m
//  ArrayDemo
//
//  Created by apple on 16/02/13.
//  Copyright (c) 2013 apple. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.
  
    double name[2];
    //name[0],name[1],name[2]
  
    name[1]=200.00;
    name[0]=100.00;
    double MyVal=300.00;
  
  
    //NSLog(@"name[0])------>%.2f",name[0]);
  
   // NSLog(@"name[1])------->%.2f",name[1]);

    //NSLog(@"myValue)------->%.2f",MyVal);
  
  
    double MyVal1=300.00;
    double names[2]={100.0,200.0,MyVal1};
  
    NSLog(@"names[0])------>%.2f",names[0]);  
     NSLog(@"names[1])------->%.2f",names[1]);  
    NSLog(@"names[2])------>%.2f",names[2]);  
  
  
  
  
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.
}
@end


1)NSArray:

It is a static Array
if we create obj once we cant remove obj
occupies less memory
add obj during initialigation









code for NSArray: 

//
//  main.m
//  NSAraayDemo
//
//  Created by apple on 16/02/13.
//  Copyright (c) 2013 apple. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
    @autoreleasepool {      
        // insert code here...
        NSLog(@"Hello, World!");      
     /*       NSArray *names=[[NSArray alloc]initWithObjects:@"naveen",@"Raja",@"Sandeep",nil];
      
        NSLog(@"%@",[names objectAtIndex:1]);
      
        for(int i=0;i<[names count];i++)
        {
            NSLog(@"%@",[names objectAtIndex:i]);
      
        }*/
      
      
      
      
      
      
        NSArray *Details = [NSArray arrayWithObjects:    [NSDictionary dictionaryWithObjectsAndKeys:    @"Naveen", @"name",[NSNumber numberWithInt: 21], @"age",[NSNumber numberWithInt: 23], @"num",nil],                           
    
                          
[NSDictionary dictionaryWithObjectsAndKeys:@"Raja", @"name",[NSNumber numberWithInt:23], @"age",[NSNumber numberWithInt: 2], @"num",nil],  
                          
                          
[NSDictionary dictionaryWithObjectsAndKeys:@"Sandeep", @"name",[NSNumber numberWithInt: 20], @"age",[NSNumber numberWithInt: 3], @"num",nil],                             nil];
      
      
      
   // NSLog(@"%@",[Details objectAtIndex:1]);
      
        for(int i=0;i<[Details count];i++){
      
        NSLog(@"%@",[Details objectAtIndex:i]);
      
        }
      
     
    }
    return 0;
}


2)NSMutabuleArray:

It is an Dynamic Array(Mutabule)
it changes the values inside existing Array Obj
occupies more mem


Mehods:

addObjectinsertObjectreplaceObjectAtIndexremoveObjectAtIndexremoveLastIndexremoveAllObjects







Code For NSMutabuleArray:


//
//  main.m
//  MutabuleArrayDemo
//
//  Created by apple on 17/02/13.
//  Copyright (c) 2013 apple. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
    @autoreleasepool {      
        // insert code here...
        NSLog(@"Hello, World!");      
       //NSMutsbule array Declaration1
      
        NSMutableArray *names=[[NSMutableArray alloc]init];      
        //adding names to an array
        [names addObject:@"Naveen"];
        [names addObject:@"Sandeep"];
        [names addObject:@"Raju"];
      
        for(NSString *name in names)
        {
            NSLog([NSString stringWithFormat:@"names--->%@",name]);        }
      
        //NSMutsbule array Declaration2
        NSMutableArray *names1=[[NSMutableArray alloc]initWithCapacity:23];        [names1 addObject:@"Hyderabad"];
        [names1 addObject:@"Bangalore"];
        [names1 addObject:@"Channai"];
        //replacing at index 1
        [names1 replaceObjectAtIndex:1 withObject:@"Delhi"];        //Removing Index
        [names1 removeObjectAtIndex:1];//Delhi removed      
      
        //removing Last Index
        [names1 removeLastObject];//Chennai Removed      
        //After Removing again Adding
        [names1 addObject:@"Bangalore"];
        [names1 addObject:@"Channai"];
        //remove All
        [names1 removeAllObjects];
      
for(NSString *State in names1)
{
    NSLog([NSString stringWithFormat:@"States----->%@",State]);}
 
      
      
      
      
      
      
    }
    return 0;
}



                        

Structures:

It is a user defined Data Type we can store diff data under unique name

typedef is to create a new type name for builtin type

Code for Structures:


//
//  main.m
//  StrctureDemo
//
//  Created by apple on 17/02/13.
//  Copyright (c) 2013 apple. All rights reserved.
//
#import <Foundation/Foundation.h>


typedef struct
{
  
    float Sal;
    double AnualSal;
    char *name;
}Details;

int main(int argc, const char * argv[])
{
    @autoreleasepool {      
        // insert code here...
        NSLog(@"Hello, World!");      
        Details det,det2,det3;
      
      
        //for Details 1
        det.Sal=25000;
        det.AnualSal=3.6;
        det.name="Naveen";
        NSLog(@"Employee Name  is %s",det.name);
        NSLog(@"Sal is %.2f",det.Sal);
        NSLog(@"Anual Sal IS %.2f",det.AnualSal);      
      
      
      
        //Details 2
        det2.Sal=15000;
        det2.AnualSal=2.1;
        det2.name="Sandeep";
        NSLog(@"Employee Name2  is %s",det2.name);      
        NSLog(@"Sal2 is %.2f",det2.Sal);
        NSLog(@"Anual Sal2 IS %.2f",det2.AnualSal);      
      
      
        //Details 3
      
        det3=det;
        NSLog(@"name3--->%s",det3.name);
        NSLog(@"Sal3---> %.2f",det3.Sal);
        NSLog(@"Anual Sal3 -->%.2f",det3.AnualSal);      
    }
    return 0;
}


No comments:

Post a Comment