Saturday 19 March 2016

iOS interview questions

  1. What is the difference between underscore and self (i.e self.xx and _xx) ?
  2. What is property?
  3. What is the difference between weak and strong?
  4. What is Retain Cycle? And how we can avoid it?
  5. What does copy means while declaring a property?
  6. What is synthesize and when we need to use it?
  7. What is a category?
  8. What is an extension?
  9. How we can add a property in a category?
  10. What is method swizzling and when we should use it?
  11. How we can layout subviews in a view?
  12. What are the size classes?
  13. What is ARC?
  14. What is @autorelease and when we should use it?
  15. How to animate view with constraint?
  16. What is core data?
  17. What is core data stack?
  18. What is managed object context?
  19. How we can do multithreading with core data?
  20. How to transfer manage object from one thread to another thread?
  21. How to merge changes from one moc to another?
  22. Difference between bounds and frame?
  23. What does dispatch_once do?
  24. What is delegate?
  25. How we can do multithreading in iOS?
  26. When you will use NSOperations over GCDs and vice versa?
  27. What does alloc do?
  28. How we can create a class in objective c which don’t inherit from NSObject?
  29. What are the different application states in iOS?
  30. How we can execute some code when app is in background?
  31. How we can wait for some thread to finish before starting another?
  32. How you will store user info (username, password or token) securely in iOS?

Saturday 23 July 2011

How to set rounded corner border of UIImageview

Steps to implements:

1] First add "Quardcore" framework and import it.
2] In view did load method write following code snippet
  • imgview.layer.borderwidth=5.0;
  • imgview.layer.cornerradios=10.0;

Tuesday 21 June 2011

Soap webservice integration with iOS using ASIHTTP

Steps to implement

1) Send request to your web server
ASIHTTPRequest * request=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://your web service url"]];

2) Create soap message body
NSString *soapMessage = [NSString stringWithFormat:@""
@""
@""
@"Your web service method"
@"
"
@"
"];

3) Add header to request
[request addRequestHeader:@"SOAPAction" value:@"http://temp_url/your_webservice_method"];

4) Append data with encoding
[request appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

5) Set request method
[request setRequestMethod:@"POST"];

6) Set content type to xml
[request addRequestHeader:@"Content-Type" value:@"text/xml"];

7) Set Delegate
request.delegate=self;

8) Set finish selector
 [request setDidFinishSelector:@selector(queue_requestDidFinish:)];

Tuesday 24 May 2011

Custom Tabbar for iOS

// mytabbar.h
#import

@class AppDelegate;

@interface mytabbar :UITabBarController
{
       AppDelegate *appDelegate;
       NSMutableArray *arrayofButton;
       BOOL isRotate;
}
@property (nonatomic,retain) NSMutableArray *arrayofButton;
-(void) tabBarAction:(UIButton*)sender;
-(void) setFrameForPortrait;
-(void) setFrameForLandScap;
@end

*******************
// mytabbar.m
*******************
#import mytabbar.h"
#import "myvc1.h"
#import "myvc2.h"


@implementation mytabbar
@synthesize arrayofButton;

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

- (void)viewDidLoad {

 [super viewDidLoad];
   appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
   self.tabBarController.delegate=self;
   arrayofButton = [[NSMutableArray alloc] init];
   self.view.autoresizesSubviews=YES;
   self.view.autoresizingMask=UIViewAutoresizingFlexibleHeight||UIViewAutoresizingFlexibleWidth;
   NSMutableArray *controllerarray=[[NSMutableArray alloc] init];
   UIImageView *tabBarBG=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Toll_bar.png"]];
  tabBarBG.frame=CGRectMake(0, 0, 1024,50);
  [self.tabBar addSubview:tabBarBG];

   myvc1 *loc=[[myvc1 alloc] initWithNibName:@"myvc1" bundle:nil];
   UINavigationController *nav_loc=[[UINavigationController alloc] initWithRootViewController:loc];
   [nav_loc setNavigationBarHidden:FALSE];
   loc.tabBarItem.image=[UIImage imageNamed:@"tabTempImage1.png"];
   loc.tabBarItem.title=@"Locations";
   [controllerarray addObject:loc];
   [nav_loc release];
   [loc release];

   myvc2 *loc2=[[myvc1 alloc] initWithNibName:@"myvc1" bundle:nil];
   UINavigationController *nav_loc2=[[UINavigationController alloc] initWithRootViewController:loc2];
   [nav_loc2 setNavigationBarHidden:FALSE];
   loc2.tabBarItem.image=[UIImage imageNamed:@"tabTempImage1.png"];
   loc2.tabBarItem.title=@"Locations";
   [controllerarray addObject:loc2];
   [nav_loc2 release];
   [loc2 release];

   self.viewControllers=controllerarray;
   [controllerarray release];
   isRotate=NO;
}


-(void)viewDidAppear:(BOOL)animated
{
 [super viewDidAppear:YES];
 UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];

 [self.tabBar addSubview:btn1];

 [btn1 setImage:[UIImage imageNamed:@"Tab0.png"] forState:UIControlStateNormal];
 [btn1 setImage:[UIImage imageNamed:@"Tab0_s.png"] forState:UIControlStateSelected];
 btn1.tag = 0;
 btn1.frame = CGRectMake(0+109,0,110, 48);
 [btn1 addTarget:self action:@selector(tabBarAction:) forControlEvents:UIControlEventTouchUpInside];
 [arrayofButton addObject:btn1];

 UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
 [self.tabBar addSubview:btn2];
 [btn2 setImage:[UIImage imageNamed:@"Tab1.png"] forState:UIControlStateNormal];
 [btn2 setImage:[UIImage imageNamed:@"Tab1_s.png"] forState:UIControlStateSelected];

 //[btn2 setTitle:@"Sosh" forState:UIControlStateNormal];
 btn2.tag = 1;
 btn2.frame = CGRectMake(219,0,110, 48);
 [btn2 addTarget:self action:@selector(tabBarAction:) forControlEvents:UIControlEventTouchUpInside];
 [arrayofButton addObject:btn2];

 [btn2 setSelected:YES];

 self.selectedIndex=1;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
 [super didReceiveMemoryWarning];

// Release any cached data, images, etc. that aren't in use.
}

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


- (void)dealloc {
  [super dealloc];
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
 UIButton *b = [arrayofButton objectAtIndex:tabBarController.selectedIndex];
 [self tabBarAction:b];

}

-(void) tabBarAction:(UIButton*)sender{

  UIButton *btn = sender;

  self.selectedIndex = btn.tag;
  for (int i=0; i < [arrayofButton count]; i++) {
  UIButton *b = [arrayofButton objectAtIndex:i];
  [b setSelected:NO];

}
 self.selectedIndex =0;
 self.selectedIndex=btn.tag;
 [btn setSelected:YES];

}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

if( interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown )
{ [self setFrameForPortrait];



}
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
   [self setFrameForLandScap];
}
return YES;


}
-(void) setFrameForPortrait{
 int temp=109;
 NSLog(@"setFrameForPortrait=%f",  self.tabBarController.tabBar.frame.origin.x);
 //[self.tabBarController.tabBar setFrame:CGRectMake(0, 0, 768, 50)];
 for (int i=0; i < [arrayofButton count] ; i++)
{
  UIButton *b = [arrayofButton objectAtIndex:i];
   if(i==0)
   {
     b.frame = CGRectMake(i+temp, 0, 110, 48);
   }else {
     b.frame = CGRectMake(i*110+temp, 0, 110, 48);
  }
 }
}

-(void) setFrameForLandScap{
  CGRect cg=self.tabBarController.selectedViewController.view.frame;
  NSLog(@"setFrameForLandScap=%@", NSStringFromCGRect(self.tabBarController.tabBar.frame));
  //[self.tabBarController.tabBar setFrame:CGRectMake(0, 0, 1024, 50)];
  NSLog(@"%@",NSStringFromCGRect(cg));
  int temp=237;
  for (int i=0; i < [arrayofButton count] ; i++) {
    UIButton *b = [arrayofButton objectAtIndex:i];
     if(i==0)
    {
     b.frame = CGRectMake(i+temp, 0, 110, 48);
    }else {
     b.frame = CGRectMake(i*110+temp,0, 110, 48);
   }
}
}

@end

Friday 20 May 2011

Twitter integration with OAuth for iOS

Step by step guide for connecting to twitter with OAuth.
You can download source code as well as SDK from below link:

More..

iOS interview questions

What is the difference between underscore and self (i.e self . xx and _xx)  ? What is property? What is the difference between weak and ...