Thursday, 27 March 2014

Fibonacci series using objective C

-(void)Fibonacci
{
     int range = 15;
    NSMutableArray* arr = [[NSMutableArray alloc]init];
    for (int k =0; k< range; k++)
    {
        if(k<2)
        {
           [arr addObject:[NSString stringWithFormat:@"%d",k]];
            continue;
        }
        else
        {
            int fib = [[arr objectAtIndex:k-2] intValue] + [[arr objectAtIndex:k-1] intValue];
            [arr addObject:[NSString stringWithFormat:@"%d",fib]];
        }
       
    }
    
     NSLog(@"%@",arr);
    

}

Output : 2014-03-27 17:31:05.284 Sqlite3[2844:70b] (
    0,
    1,
    1,
    2,
    3,
    5,
    8,
    13,
    21,
    34,
    55,
    89,
    144,
    233,
    377
)

NSURLConnection with NSOperationQueue.

-(void)connectivity
{
    NSString* urlString = @"http://four-developers.com/service1.svc/getdata/aa";
    NSURL *url = [NSURL URLWithString:urlString];
    
    //NSData* data = [[NSData alloc]init];
    
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    
    [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
    {
        if ([data length] > 0 && error == nil)
        {
            NSDictionary *jsonObject=[NSJSONSerialization
                                      JSONObjectWithData:data
                                      options:NSJSONReadingMutableLeaves
                                      error:nil];
            NSLog(@"%@",jsonObject);
            NSMutableArray* arr = [jsonObject valueForKey:@"GetDataResult"];
            NSString* strJobcategory  = [[arr objectAtIndex:0] valueForKey:@"jobCategory"];
        }
           
    }];
     

}

Thursday, 20 March 2014

difference Between category and extension in objective c

The main difference is that with an extension, the compiler will expect you to implement the methods within your main @implementation, whereas with a category you have a separate @implementation block. So you should pretty much only use an extension at the top of your main .m file (the only place you should care about ivars, incidentally) -- it's meant to be just that, an extension.

Wednesday, 5 March 2014

AFNetworking and custom cell for UITableView

Steps to get data from webservices Using AFnetworking..

1- Download the AFNetworking library from

http://four-developers.com/documents/afnetworking.zip

2 - If your is arc based then you have to add the following flag

-fno-objc-arc

to every afnetworking file..

3 - After that you have to import to your viewcontroller
#import "AFNetworking.h"
4 - After that :

Use following code..

-(void)AFnetworkingProcessTheRequest
{
    NSURLRequest* request = [[NSURLRequest alloc]initWithURL:[NSURL  URLWithString:@"http://four-developers.com/service1.svc/getdata/aa"]];
    AFJSONRequestOperation* opration = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request,NSHTTPURLResponse *response,id responseObject)
                                        {
                                            arrData = [[NSArray alloc]initWithObjects:responseObject, nil];
                                           
                                            [tblEmp  reloadData];
                                           
                                        }
                                        failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id responseObject)
                                            {
                                                NSLog(@"Request Failed: %@, %@", error, error.userInfo);
                                            }];
    [opration start];
   

}


You can download Complete sample from:

http://four-developers.com/documents/UsingAFNetWorking.zip

Tuesday, 4 March 2014

Extract resources from an .ipa or executable file for Xcode project

1. Copy the .ipa file like Test.ipa
2. Now change the extention .ipa to .zip like Test.ipa to Test.zip or   Test.ipa.zip .
  You will get alert

"Are you sure you want to change the extension from “.ipa” to “.zip”?"
"If you make this change, your document may open in a different application."


 with two options

->keep .ipa
-> use .zip
 Click on use zip and you you will get .zip file and double click on it and you will get Payload file containing a file.

3. Right click on it(file into PayLoad folder) and "Show Package Contents"