Thursday, 30 January 2014

scaling an image

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"taj.jpg"]];
    imageView.frame = CGRectMake(100, 100, 417  ,517);
    imageView.center = imageView.superview.center;

    [self.view addSubview:imageView];

Thursday, 23 January 2014

Table Without CustomCell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier=@"test";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if(cell==nil)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        
    }
    cell.textLabel.text=[arr objectAtindex:indexpath.row];
    return cell;
    

}

Wednesday, 22 January 2014

Multiple CheckBox

-(IBAction)ChkUnChk:(id)sender //To connect all buttons
{
    
    UIButton *btn=(UIButton *)sender;
    NSString *Str=[NSString stringWithFormat:@"%d",btn.tag];
    BOOL flag=   [selectedBtnarr containsObject:Str];
    
    if (flag==YES)
    {
        [btn setBackgroundImage:[UIImage imageNamed:@"A.jpg"]    forState:UIControlStateNormal];
        [selectedBtnarr removeObject:Str];
    }
    else
    {
        [selectedBtnarr addObject:Str];
        [btn setBackgroundImage:[UIImage imageNamed:@"che1.png"] forState:UIControlStateNormal];
    }

}

Single Radio Button and Checkbox

-(void)viewDidAppear:(BOOL)animated{
    
    //Checkboxes
    
    checkbutton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    [checkbutton setBackgroundImage:[UIImage imageNamed:@"check.jpeg"] forState:UIControlStateNormal];
    [checkbutton setBackgroundImage:[UIImage imageNamed:@"che1.png"] forState:UIControlStateSelected];
    [checkbutton addTarget:self action:@selector(checkboxSelected:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:checkbutton];

    //radio buttons
    radiobutton = [[UIButton alloc] initWithFrame:CGRectMake(0, 80, 20, 20)];
    [radiobutton setTag:0];
    [radiobutton setBackgroundImage:[UIImage imageNamed:@"radio.jpeg"] forState:UIControlStateNormal];
    [radiobutton setBackgroundImage:[UIImage imageNamed:@"sel.jpeg"] forState:UIControlStateSelected];
    [radiobutton addTarget:self action:@selector(radiobuttonSelected:) forControlEvents:UIControlEventTouchUpInside];
    
    radiobutton2 = [[UIButton alloc] initWithFrame:CGRectMake(80, 80, 20, 20)];
    [radiobutton2 setTag:1];
    [radiobutton2 setBackgroundImage:[UIImage imageNamed:@"radio.jpeg"] forState:UIControlStateNormal];
    [radiobutton2 setBackgroundImage:[UIImage imageNamed:@"sel.jpeg"] forState:UIControlStateSelected];
    [radiobutton2 addTarget:self action:@selector(radiobuttonSelected:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:radiobutton];
    [self.view addSubview:radiobutton2];
}

-(void)checkboxSelected:(id)sender{
    
    
    if([checkbutton isSelected]==YES)
    {
        [checkbutton setSelected:NO];
    }
    else{
        [checkbutton setSelected:YES];
    }
    
}
-(void)radiobuttonSelected:(id)sender{
    switch ([sender tag]) {
        case 0:
            if([radiobutton isSelected]==YES)
            {
                [radiobutton setSelected:NO];
                [radiobutton2 setSelected:YES];
            }
            else{
                [radiobutton setSelected:YES];
                [radiobutton2 setSelected:NO];
            }
            
            break;
        case 1:
            if([radiobutton2 isSelected]==YES)
            {
                [radiobutton2 setSelected:NO];
                [radiobutton setSelected:YES];
            }
            else{
                [radiobutton2 setSelected:YES];
                [radiobutton setSelected:NO];
            }
            
            break;
        default:
            break;
    }
    

}

Gesture Program

//Add framwork
iAd.framework

//ViewController.H
#import <iAd/iAd.h>
@interface ViewController : UIViewController<ADBannerViewDelegate>
@property (strong, nonatomic) IBOutlet UILabel *statusLabel;

@property (strong, nonatomic) IBOutlet ADBannerView *bannerView;

//ViewController.M
@implementation ViewController
@synthesize statusLabel,bannerView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    bannerView = [[ADBannerView alloc]initWithFrame:
                  CGRectMake(0, 0, 320, 50)];
    // Optional to set background color to clear color
    [bannerView setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview: bannerView];
    
    
    UITapGestureRecognizer *doubleTap =
    [[UITapGestureRecognizer alloc]
     initWithTarget:self
     action:@selector(tapDetected:)];
    doubleTap.numberOfTapsRequired = 2;
    [self.view addGestureRecognizer:doubleTap];
    //[doubleTap release];
    
    UIPinchGestureRecognizer *pinchRecognizer =
    [[UIPinchGestureRecognizer alloc]
     initWithTarget:self
     action:@selector(pinchDetected:)];
    [self.view addGestureRecognizer:pinchRecognizer];
    //[pinchRecognizer release];
    
    UIRotationGestureRecognizer *rotationRecognizer =
    [[UIRotationGestureRecognizer alloc]
     initWithTarget:self
     action:@selector(rotationDetected:)];
    [self.view addGestureRecognizer:rotationRecognizer];
    //[rotationRecognizer release];
    
    UISwipeGestureRecognizer *swipeRecognizer =
    [[UISwipeGestureRecognizer alloc]
     initWithTarget:self
     action:@selector(swipeDetected:)];
    swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swipeRecognizer];
    //[swipeRecognizer release];
    
    UILongPressGestureRecognizer *longPressRecognizer =
    [[UILongPressGestureRecognizer alloc]
     initWithTarget:self
     action:@selector(longPressDetected:)];
    longPressRecognizer.minimumPressDuration = 3;
    longPressRecognizer.numberOfTouchesRequired = 1;
    [self.view addGestureRecognizer:longPressRecognizer];
    //[longPressRecognizer release];
    [super viewDidLoad];
}
// Do any additional setup after loading the view, typically from a nib.


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)longPressDetected:(UIGestureRecognizer *)sender {
    statusLabel.text = @"Long Press";
}

- (IBAction)swipeDetected:(UIGestureRecognizer *)sender {
    statusLabel.text = @"Right Swipe";
}

- (IBAction)tapDetected:(UIGestureRecognizer *)sender {
    statusLabel.text = @"Double Tap";
}

- (IBAction)pinchDetected:(UIGestureRecognizer *)sender {
    
    CGFloat scale =
    [(UIPinchGestureRecognizer *)sender scale];
    CGFloat velocity =
    [(UIPinchGestureRecognizer *)sender velocity];
    
    NSString *resultString = [[NSString alloc] initWithFormat:
                              @"Pinch - scale = %f, velocity = %f",
                              scale, velocity];
    statusLabel.text = resultString;
    }

- (IBAction)rotationDetected:(UIGestureRecognizer *)sender {
    CGFloat radians =
    [(UIRotationGestureRecognizer *)sender rotation];
    CGFloat velocity =
    [(UIRotationGestureRecognizer *)sender velocity];
    
    NSString *resultString = [[NSString alloc] initWithFormat:
                              @"Rotation - Radians = %f, velocity = %f",
                              radians, velocity];
    statusLabel.text = resultString;
    }

-(void)bannerView:(ADBannerView *)banner
didFailToReceiveAdWithError:(NSError *)error{
    NSLog(@"Error loading");
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
    NSLog(@"Ad loaded");
}
-(void)bannerViewWillLoadAd:(ADBannerView *)banner{
    NSLog(@"Ad will load");
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
    NSLog(@"Ad did finish");
    
}

Create Grid

-(void) layoutGrid {
         
         
         UIColor *c3;
         UIScrollView *sc=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 480, 320)];
         sc.userInteractionEnabled=YES;
         sc.backgroundColor=[UIColor purpleColor];
         sc.delegate=self;
         sc.scrollEnabled=YES;
         sc.contentSize=CGSizeMake(1000,800);
         [self.view addSubview:sc];
                  NSInteger grid[20][20];
         NSInteger k = 0;
         for (int row = 0; row <10; row++) {
             
             for (int column = 0; column <20; column++) {
                 if(column%2==0){
                     c3=[UIColor blackColor];
                 }
                 else{
                     c3=[UIColor whiteColor];
                 }
                 k++;
                 grid[row][column] = k;
                 UIView *lbl = [[UIView alloc] initWithFrame:CGRectMake(column*50, row * 50, 40, 40)];
                 [lbl setBackgroundColor:c3];
                
                 [sc addSubview:lbl];
         
                                  sc.userInteractionEnabled=YES;
             }
         }
         

     }

Reverse A string

NSString *s=text.text;

    int i=[s length];
    NSMutableString *arr=[[NSMutableString alloc]initWithCapacity:i];
    for ( int j=i-1; j>=0; j--) {
        [arr appendString:[NSString stringWithFormat:@"%c",[s characterAtIndex:j]]];
    }

    NSLog(@"%@",arr);

Preference

Header File:

<UIImagePickerControllerDelegate, UINavigationControllerDelegate>


//ViewController.M
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    // Get the stored data before the view loads
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *firstName = [defaults objectForKey:@"firstName"];
    NSData *imageData = [defaults dataForKey:@"image"];
    UIImage *contactImage = [UIImage imageWithData:imageData];
    // Update the UI elements with the saved data
    txt_name.text = firstName;
    
    img_photo.image = contactImage;
}

- (void)viewDidUnload
{
    [self setTxt_name:nil];
    [self setImg_photo:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)Save:(id)sender 
{
    // Create strings and integer to store the text info
    NSString *firstName = [txt_name text];
    
    
    // Create instances of NSData
    UIImage *contactImage = img_photo.image;
    NSData *imageData = UIImageJPEGRepresentation(contactImage, 100);
    // Store the data
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:firstName forKey:@"firstName"];
    [defaults setObject:imageData forKey:@"image"];
    [defaults synchronize];
    NSLog(@"Data saved");
}

- (IBAction)Choose:(id)sender 
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
}

#pragma mark - Image Picker Delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    img_photo.image = image;
    [picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissModalViewControllerAnimated:YES];

}

PList

//PList path
    NSString *path = [[NSBundle mainBundle] pathForResource:@"PropertyList" ofType:@"plist"];

    stringArray = [[NSMutableArray alloc] initWithContentsOfFile:path];

System Date And Time

//ViewController.H

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    NSDate *date;
    
}
//ViewController.M
date=[NSDate date];
    NSDateFormatter *dateformat=[[NSDateFormatter alloc]init];
    [dateformat setDateFormat:@"HH:mm:ss \n dd:MM:YYYY"];
    NSString *string1=[dateformat stringFromDate:date];

    labletime.text=string1;

SQL Without FMDB

- (void)viewDidLoad
{
    
    NSString *docsDir;
    NSArray *dirPaths;
    //dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    docsDir = [dirPaths objectAtIndex:0];//
    databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"contacts.db"]];
     NSFileManager *filemgr = [NSFileManager defaultManager];
    if ([filemgr fileExistsAtPath: databasePath])
    {
        const char *dbpath = [databasePath UTF8String];
    
        if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
        {
            char *errMsg;
            const char *sql_stmt = "CREATE TABLE IF NOT EXISTS CONTACTS(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, ADDRESS TEXT, PHONE TEXT)";
            if (sqlite3_exec(contactDB, sql_stmt, NULL, NULL, &errMsg)!= SQLITE_OK)
            {
                status.text = @"Failed to Create Table";
            }
            sqlite3_close(contactDB);
        }
        else
        {
            status.text = @"Failed to Open/Create Database";
        }
    }
    
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
//SAVED
- (void) saveData
{
    
    sqlite3_stmt *statement;
    const char *dbpath = [databasePath UTF8String];
    NSLog(@"%s",dbpath);
    if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK )
    {
        NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO CONTACTS (name, address, phone) VALUES (\"%@\", \"%@\", \"%@\")", name.text, address.text, phone.text];
        const char *insert_stmt = [insertSQL UTF8String];
        
        sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
        if (sqlite3_step(statement) == SQLITE_DONE)
        {
            status.text = @"Contact Added";
            name.text = @"";
            address.text = @"";
            phone.text = @"";
        }
        else
        {
            status.text = @"Failed to Add Contact";
        }
        sqlite3_finalize(statement);
        sqlite3_close(contactDB);
    }
    
    

}

SQL-FMDB

-(void) createDatabase
{
    NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [dirPaths objectAtIndex:0];
    NSString *databasePath = [docDir stringByAppendingPathComponent:@"samcontact.sqlite"];
    
    FMDatabase *database = [FMDatabase databaseWithPath:databasePath];
    
    [database open];
    
    [database executeUpdate:@"create table phone(Name varchar, Address varchar, phoneno numeric)"];
    NSLog(@"Database created");
    NSLog(@"Path is : %@ ",databasePath);
    [database close];
}
//INSERT
- (IBAction)btn_insert:(id)sender 
{
    NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [dirPaths objectAtIndex:0];
    NSString *databasePath = [docDir stringByAppendingPathComponent:@"samcontact.sqlite"];
    
    FMDatabase *database = [FMDatabase databaseWithPath:databasePath];
    
    [database open];
    
    [database executeUpdate:@"insert into phone (Name, Address, phoneno) values(?,?,?)",txt_Name.text,txt_Address.text,txt_Contact.text];
    
    
    UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"Sample SQLite" message:@"Inserted Successfully" delegate:Nil cancelButtonTitle:@"OK"otherButtonTitles: nil];
    [alert show];
    
    [database close];
    
    txt_Name.text = @"";
    txt_Address.text = @"";
    txt_Contact.text = @"";
}
//SELECT
- (IBAction)btn_Select:(id)sender 
{
    NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [dirPaths objectAtIndex:0];
    NSString *databasePath = [docDir stringByAppendingPathComponent:@"samcontact.sqlite"];
    NSString *str;
    NSString *num;
    NSString *name;
    FMDatabase *database = [FMDatabase databaseWithPath:databasePath];
    
    [database open];
    FMResultSet *results = [database executeQuery:@"select * from phone where Name = ?",txt_Name.text];
    
     NSLog(@"select * from phone where Name = \"%@\"",txt_Name.text);
    
    while ([results next])
    {
        name = [results stringForColumn:@"Name"];
        str = [results stringForColumn:@"Address"];
        num = [results stringForColumn:@"phoneno"];
        
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"Sample SQLite" message:@"Find Successfully" delegate:Nil cancelButtonTitle:@"OK"otherButtonTitles: nil];
        [alert show];
        
    }
    txt_Name.text = name;
    txt_Address.text = str;
    txt_Contact.text = num;
    
    
    
    [database close];


}

XML

NSError *error;
    NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundlepathForResource:@"universal-science" ofType:@"xml"]];
    NSDictionary *xmlDic=[XMLReader dictionaryForXMLData:data error:&error];
    
    NSLog(@"book %@",xmlDic);
    
    NSLog(@"chapter %@",[xmlDic valueForKeyPath:@"book.chapter"]);
    
    NSLog(@"title : %@",[xmlDic valueForKeyPath:@"book.chapter.title"]);
   title_Text.text = [NSString stringWithFormat:@"%@",[xmlDic valueForKeyPath:@"book.chapter.title.text"]];
    subTitle.text=[NSString stringWithFormat:@"%@",[xmlDic valueForKeyPath:@"book.chapter.section.objectiveset.title.text"]];

    para_Text.text = [NSString stringWithFormat:@"%@",[xmlDic valueForKeyPath:@"book.chapter.section.objectiveset.objective.para.text"]];

Custom Cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *identifier=@"treat";
    customcell *cell=[table dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
        NSArray *arr=[[NSBundle mainBundle]loadNibNamed:@"customcell" owner:nil options:nil];
        for (UIView *v in arr) {
            if ([v isKindOfClass:[UITableViewCell class]]) {
                cell=(customcell*)v;
            }
        }
    }
    cell.label.text=[array objectAtIndex:indexPath.row];
    UIImage *img=[UIImage imageNamed:[array objectAtIndex:indexPath.row]];
    [cell.image setImage:img forState:UIControlStateNormal];
    if (indexPath.row==1) {
    cell.accessoryType=UITableViewCellAccessoryCheckmark;
    }
    else if (indexPath.row==5){
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

    }
    else
    {
        cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
    }
    return cell;

}

Counting the particular words

str = @"Cricket is a bat-and-ball game played between two teams of 11 players on a field,at the center of which is a rectangular 22-yard long pitch.one team bats,trying to score as many run as possible while the other team bowels and fields,trying to dissmiss the batsmen and thus limit the runs scored by the batting team.A run is scored by the striking batsman hitting the ball with his bat,running to the opposite end of the pith and touching the crease there without being dismissed.The teams switch between batting and fielding at the end of an innings. ";

    NSString *s=textbox.text;  //Type the word here
    NSRange r = NSMakeRange(0, str.length);
    int count = 0;
    for (;;) {
        r = [str rangeOfString:s options:NSCaseInsensitiveSearch range:r];
        if (r.location == NSNotFound) {
            break;
        }
        count++;
        r.location++;
        r.length = str.length - r.location;
    }

label.text=[NSString stringWithFormat:@"%d",count];

Distinct Item

ar=[[NSArray alloc]initWithObjects:@"sachin",@"saurav",@"dada",@"dhoni",@"viru",@"raina",@"morkel",@"cricket",@"saurav",@"sachin",@"badri",@"yuvi",@"bhajji",@"gauti",@"umesh",@"yusuf",@"gauti", nil];
     //arr1=[[NSArray alloc]initWithObjects:@"sachin",@"saurav",@"dada",@"dhoni",@"viru",@"raina",@"morkel",@"cricket",@"saurav",@"sachin",@"badri",@"yuvi",@"bhajji",@"gauti",@"umesh",@"yusuf",@"gauti", nil];
    crt=[[NSMutableArray alloc]init];

//Display Repeated Items only
- (IBAction)click:(id)sender {
    for(int i=0;i<[ar count];i++)
    {
        for(int j=i+1;j<[ar count];j++)
        {
            if([[ar objectAtIndex:i] isEqualToString:[ar objectAtIndex:j]])
            {
                [crt addObject:[ar objectAtIndex:i]];
                break;
            }
        }
    }
    for (int i=0; i<[crt count]; i++) {
    label1.text=[ label1.text stringByAppendingString:[NSString stringWithFormat:@"%@ \n",[crt objectAtIndex:i]]];
    }
}
//Display Without repeated Item
- (IBAction)distinct:(id)sender {
    NSArray *a2 = [[NSOrderedSet orderedSetWithArray:ar] array];
    for (int a=0; a<[a2 count]; a++)
    {
         label2.text=[label2.text stringByAppendingString:[NSString stringWithFormat:@"%@ \n",[a2 objectAtIndex:a]]];
    }


}

Swap array objects

//When clicking button it change different
- (IBAction)click:(id)sender {
    /*[ar replaceObjectAtIndex:0 withObject:[ar objectAtIndex:2]];
    [ar replaceObjectAtIndex:1 withObject:[ar objectAtIndex:0]];
    [ar replaceObjectAtIndex:2 withObject:[ar objectAtIndex:1]];
    */
    NSUInteger count = [ar count];
    for (NSUInteger i = 0; i < count; ++i) {
        int nElements = count - i;
        int n = (arc4random() % nElements) + i;
        [ar exchangeObjectAtIndex:i withObjectAtIndex:n];
        
    }
    t1.text=[ar objectAtIndex:0];
    t2.text=[ar objectAtIndex:1];
    t3.text=[ar objectAtIndex:2];

}

Dictionary Concepts

- (void)viewDidLoad
{
    [super viewDidLoad];
    dic=[[NSDictionary alloc]initWithObjectsAndKeys:@"userName",@"yuva",@"passWord",@"yuva", nil];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)click:(id)sender 
        
  //creating nsdictionary
    NSString *a=t1.text;
    NSString *a1=t2.text;
    NSString *a2=t3.text;
    NSDictionary *user1=[NSDictionary dictionaryWithObjectsAndKeys:a,@"username",a1,@"password",a2,@"key", nil];

//    NSMutableDictionary *u2=[NSMutableDictionary dictionary];
//    [u2 setObject:@"aaa" forKey:@"username"];
//    [u2 setObject:@"bbb" forKey:@"username"];
//    [u2 setObject:@"12" forKey:@"password"];
//    [u2 setObject:@"23" forKey:@"password"];
    //NSMutableArray *accounts = [NSMutableArray arrayWithObjects:user,user1,userAccount, nil];
        // do something with accounts

   Copy Dic to MutableDic
    //**********************
    NSMutableDictionary *dic;
    dic=[user1 mutableCopy];
    *************************
   
    NSString *str=[NSString stringWithFormat:@"%@",user1];
    tex1.text=[NSString stringWithFormat:@"NSDictionary string\n %@ \n\n\n NSmutabledictionary\n %@",str,dic];

   // NSMutableDictionary *dictionary=[[NSMutableDictionary alloc]initWithDictionary:user1];

}

Map with MultipleAnnatation

- (void)viewDidLoad
{
    [super viewDidLoad];
    map.delegate=self;
    map.showsUserLocation=YES;
    [self show];
    [self annonation];
    alertInfoArray=[[NSArray alloc]init];
  
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)show{
    longatt=[[NSArray alloc]initWithObjects:[NSNumber numberWithFloat:72.87766],[NSNumber numberWithDouble:77.22496],[NSNumber numberWithDouble:78.70467],[NSNumber numberWithDouble:76.27108],[NSNumber numberWithDouble:77.594563], nil];
    lat=[[NSArray alloc]initWithObjects:[NSNumber numberWithFloat:19.07598],[NSNumber numberWithFloat:28.63531],[NSNumber numberWithFloat:10.79048],[NSNumber numberWithFloat:10.85052],[NSNumber numberWithFloat:12.971599], nil];
    title1=[[NSArray alloc]initWithObjects:@"Mumbai",@"Delhi",@"Trichy",@"kerala",@"Bangalore", nil];
    for (int i=0; i<[longatt count]; i++)
    {
    CLLocationCoordinate2D center;
    center.latitude=[[lat objectAtIndex:i]floatValue];
    center.longitude=[[longatt objectAtIndex:i]floatValue];
    MKCoordinateRegion reg;
    reg.center=center;
    [map setRegion:reg];
    }
    
}
-(void)annonation{
    for(int i=0;i<4;i++){
    CLLocationCoordinate2D newcenter;
    newcenter.latitude=[[lat objectAtIndex:i] floatValue];
    newcenter.longitude=[[longatt objectAtIndex:i]floatValue] ;
    MKPointAnnotation *pin=[[MKPointAnnotation alloc ]init];
    //[pin setCoordinate:newcenter];
        pin.coordinate=newcenter;
    pin.title=[title1 objectAtIndex:i];
        
        [map addAnnotation:pin];
    }
    
    

}

Download a File

NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.dowling.edu/careerservices/sampleresume.pdf"]];
    
    //Store the Data locally as PDF File
    
    NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundleresourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents"]];
    
    NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"sampleresume.pdf"];
    
    [pdfData writeToFile:filePath atomically:YES];
    
    
    //Now create Request for the file that was saved in your documents folder
    
    NSURL *url = [NSURL fileURLWithPath:filePath];
    
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    
    [webView setUserInteractionEnabled:YES];
    
    [webView setDelegate:self];
    

    [webView loadRequest:requestObj];

JSON

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    [mdata  setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    [mdata appendData:data];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    NSError *err;
    NSString *str=[[NSJSONSerialization JSONObjectWithData:mdata options:-1 error:&err] description];
    //NSLog(@"%@",err.localizedDescription);
  t1.text=str;
 NSLog(@"Succeeded! Received %d bytes of data",[mData length]);//Bytes Received
   NSLog(@"The received data are%@",mData); 
}
- (IBAction)click:(id)sender {
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.googleapis.com/youtube/v3/videos"]];
    
    NSURLConnection *connection=[NSURLConnection connectionWithRequest:request delegate:self];
    if(connection)
    {
        mdata=[NSMutableData data];
        [connection start];
    }


}