Wednesday, November 6, 2013

jSON Parsing for array of dictionaries in iOS

Class created by me for jSON parsing.
iOS developers, this class has method to parse (array of dictionaries).
Feel free to update the class for other type of JSON response strings as well.


https://github.com/ashish9855/jsonParsing


Tuesday, October 22, 2013

Delegate Design Pattern in iOS

About: -

Suppose there is message passing between two objects X, Y.
Suppose an employee and a boss, when employee finishes his task and he has to inform boss about that how would it do?

This is possible in terms of delegate. When X and Y are two objects like employee and boss and as soon as X finishes its task Y is told about it.

Features: -

1.     The main thing is reducing the interdependency of classes.
2.     To make the class more reusable.
3.     Al l the methods of delegate are in protocol, where the person can set required or optional.
4.     Required are compulsory for the delegate to implement.
5.     Optional are not compulsory for the delegate to implement.

Below is the link of git repository to download the delegate sample code: -


Have fun.. !!! Any problems post in comments.

Sunday, September 22, 2013

Creating dynamic scroll view of iOS

This  would create a scroll view which would be divided into two parts in the view.
The images would automatically change there size and adjust there frames accordingly.
This would also have a name below it as well which would adjust according to the image.

You can download the project from here :-

https://bitbucket.org/ashish9855/oscroll

Sunday, August 18, 2013

error in ASIHTTPRequest

This  is a very common error you would face.

You have to include a bundle which is as: libxml2.dylib. 

Go to project Build settingd search for Header Search Paths

and double click and add:-  $(SDKROOT)/usr/include/libxml2


It would work fine.

Creating Asynchronous request for Soap WebService with ASIHTTPRequest

Follow the steps below: -

1) Visit: - http://allseeing-i.com/ASIHTTPRequest/Setup-instructions

Go to this link and download classes which are as told.

2) Read this code for easy understanding:- 

//
//  demoViewController.m
//  SendAsynchronousRequest
//
//  Created by Ashish on 8/17/13.
//  Copyright (c) 2013 ashish. All rights reserved.
//

#import "demoViewController.h"
#import "ASIHTTPRequest.h"
#import "ASIHTTPRequestDelegate.h"
#import "ASINetworkQueue.h"
#import "ASIFormDataRequest.h"

@interface demoViewController ()

@end


@implementation demoViewController

NSMutableString *getData;
NSMutableString *getData1;
NSMutableString *getData2;

//XML Parser
//---xml parsing---
NSXMLParser *xmlParser;
NSMutableString *soapResults;
BOOL elementFound;
int flag;
NSMutableData *webData;


@synthesize activity,MainCatId;

-(void)connectionString
{
   
    [activity startAnimating];
   
    NSURL *url=[NSURL URLWithString:@""];
   
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
   
    [request setDelegate:self];
   
    [request setRequestMethod:@"POST"];
   
    [request addRequestHeader:@"Content-Type" value:@"text/xml"];
   
    [request addRequestHeader:@"SOAPAction" value:@"http://tempuri.org/Search"];
   
    NSString *soapString=[NSString stringWithFormat:
                          @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
]";
    NSLog(@"%@",soapString);
  
   

    NSString *msgLength =[NSString stringWithFormat:@"%d", [soapString length]];
   
    [request addRequestHeader:@"Content-Length" value:msgLength];
   
    [request appendPostData:[soapString dataUsingEncoding:NSUTF8StringEncoding]];
   
    [request setDelegate:self];
   
    [request setDidFinishSelector:@selector(requestDone:)];
   
    [request setDidFailSelector:@selector(requestWentWrong:)];
   
    [request startAsynchronous];
   
   
    if (request)
    {
        webData = [NSMutableData data];
       
        //NSLog(@"response= %@",responseData);
    }

   
   
}


-(void)parseUser:(NSString *)xml{
   
   
    NSData* data=[xml dataUsingEncoding:NSUTF8StringEncoding];
   
    xmlParser = [[NSXMLParser alloc] initWithData:data];
    [xmlParser setDelegate:self];
    [xmlParser setShouldProcessNamespaces:NO];
    [xmlParser setShouldReportNamespacePrefixes:NO];
    [xmlParser setShouldResolveExternalEntities:NO];
    [xmlParser parse];
   
}


# pragma mark View Connection Functionalities

-(void) connection:(NSURLConnection *) connection
didReceiveResponse:(NSURLResponse *) response {
    [webData setLength: 0];
    // NSLog(@"didReceiveResponse");
}

-(void) connection:(NSURLConnection *) connection
    didReceiveData:(NSData *) data {
    [webData appendData:data];
    //NSLog(@"didReceiveData");
}


-(void) parser:(NSXMLParser *) parser
didStartElement:(NSString *) elementName
  namespaceURI:(NSString *) namespaceURI
 qualifiedName:(NSString *) qName
    attributes:(NSDictionary *) attributeDict {
   
    //    CurrentElement = [elementName copy];
    //    NSUserDefaults *userdefaults=[NSUserDefaults standardUserDefaults];
   
    NSLog(@"Element name %@%@",elementName,soapResults);
   
    if( [elementName isEqualToString:@"NewDataSet"])      //enter the tag you want to start
    {
        if (!soapResults)
        {
            soapResults = [[NSMutableString alloc] init];
        }
        elementFound = true;
    }
   
}

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
    if(elementFound)
    {
       
        soapResults = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        NSLog(@"soap results %@",soapResults);
    }
   
   
}

-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
 namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
   
    if([elementName isEqualToString:@""])
    {
        [arr1 addObject:soapResults];

    }
   
    if([elementName isEqualToString:@""])
    {
        [arr2 addObject:soapResults];
        }
   
    if([elementName isEqualToString:@""])
    {
        [arr3 addObject:soapResults];

    }
      
}


- (void)requestDone:(ASIHTTPRequest *)request{
   
    NSString *response = [request responseString];
   
    NSLog(@"%@",response);
   
    [self parseUser:response];
   
              
       
        [activity stopAnimating];
       
        activity.hidden=TRUE;
       
    }
   

- (void)requestWentWrong:(ASIHTTPRequest *)request

{
    NSError *error = [request error];
   
    NSLog(@"%@",error);
   
}


- (void)viewDidLoad
{
    [super viewDidLoad];
   

    [self connectionString];
   
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


Monday, August 12, 2013

create your ideas into reality

What are you waiting for.. 

Stop spending more time , money, resources.
Just Contact :- a.maheshwari9855@gmail.com
and turn your ideas into reality. 

Platforms:- iOS, Windows Phone, .Net (softwares, Websites)

We wont let you and your idea down. It is as important for us as much as for you.

College startups a great opportunity for you, your ideas will be live without spending much.

We would assist you at every point.

College final year projects: why waste your time in searching on the internet when you can get the full fledged stuff here. With the documentation. 
Do smart work and score smartly.

Convert your ideas into reality

What are you waiting for.. 

Stop spending more time , money, resources.
Just Contact :- a.maheshwari9855@gmail.com
and turn your ideas into reality. 

Platforms:- iOS, Windows Phone, .Net (softwares, Websites)

We wont let you and your idea down. It is as important for us as much as for you.

College startups a great opportunity for you, your ideas will be live without spending much.

We would assist you at every point.

College final year projects: why waste your time in searching on the internet when you can get the full fledged stuff here. With the documentation. 
Do smart work and score smartly.