Wednesday, 9 April 2014

What is Extension

A class extension bears some similarity to a category, but it can only be added to a class for which you have the source code at compile time (the class is compiled at the same time as the class extension).
Extensions are actually categories without the category name. It's often referred as anonymous categories.
An extension cannot be declared for any class, only for the classes that we have original implementation of source code.
An extension is adding private methods and private variables that are only specific to the class.
Any method or variable declared inside the extensions is not accessible even to the inherited classes.

What is Block in objective c

Blocks are Objective-C’s anonymous functions. They let you pass arbitrary statements between objects as you would data, which is often more intuitive than referencing functions defined elsewhere. In addition, blocks are implemented as closures, making it trivial to capture the surrounding state

What is Polymorphism

=>Polymorphism is one of the principle of object oriented programming. "Poly" means many and "morph" means forms hence the name polymorphism.
=>Polymorphism also refered to as one name many forms or having one name with multiple functionality.
=>Use same method name with different signature or same signature but in different class.So depending on a data type it processes objects differently and an ability to redefine methods for a derived classes.

What is Abstraction ?

=> Abstraction is the act of representing essential features without including the background details or explanations. 
 => In the computer science and software engineering domain, the abstraction principle is used to reduce complexity and allow efficient design and implementation of complex software systems.

List the five iOS app states.

1) Not running -: The app has not been launched or was running but was terminated by the system.
2) Inactive -: The app is running in the foreground, but not receiving events. An iOS app can be placed into an inactive state, for example, when a call or SMS message is received.
3) Active -: The app is running in the foreground, and receiving events.
4) Background -: The app is running in the background, and executing code.
5 )Suspended -: The app is in the background, but no code is being executed

What is Category

Defination:

+A category allows you to add methods to an existing class—even to one for which you do not have the source.+Its a powerful feature that allows you to extend the functionality of existing classes without subclassing+Its a way to split a single class definition into multiple file

How to create PDF form UIWebView and Print in objective c

If you want create a PDF file from web view and print the same , then do the followings

- (void) webViewDidFinishLoad:(UIWebView *)aWebView
{
    [self createPDFfromUIView:aWebView saveToDocumentsWithFileName:@"Test"];
}
- (void) createPDFfromUIView:(UIWebView *)aView saveToDocumentsWithFileName:(NSString *)aFilename
{
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[aView.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];
NSString *documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
//[pdfData writeToFile:documentDirectoryFilename atomically:YES];// if you want to store the file in document directory
[self printPdf:documentDirectoryFilename]; //for printing PDF
}
- (void) printPdf:(NSString *)path
{
NSData *myData = [NSData dataWithContentsOfFile:path];
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
if ( pic && [UIPrintInteractionController canPrintData:myData] )
{
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = myData;
void ( ^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController * pic, BOOL completed, NSError * error) {
if (!completed && error)
{
NSLog (@”FAILED! due to error in domain %@ with error code %u”, error.domain, error.code);
}
};

[pic presentAnimated:YES completionHandler:completionHandler];
}
}

What is difference between atomic and nonatomic in objective c

ATOMIC
1)One thread access the variable(static)
2)It is a thread safe
3)Its performance is very slow
4) It is a not keyword its a accessor
5)Its is default behaviour.
6)Will ensure the present process is completed by the cpu, before another process access the variable
Ex-@property(retain) UILabel *myLabel same as @property( atomic,retain) UILabel *myLabel
NON ATOMIC
1) Its not a default behaviour
2)Its not a thread safe
3)It is a not keyword its a accessor
4)Its performance is very first.
5)Multiple thread access the variable(dynamic).
Ex-@property(nonatomic, retain) UILabel *myLabel

What is difference between NSNumber and NSInteger

NSNumber
1)INSNumber is subclass od NSValue
2)It is not primitive(like int,unsigned int,double,float etc..)
3)It store and retrieve primitive values.
4)NSNumber can be displayed with the %@ format specifier
Ex- NSNumber *floatValue = [NSNumber numberWithFloat :50.5678];
NSlog(@“%@”, floatValue);
5) Its very useful when you need to stick a number into an NSArray or NSDictionary
EX- Convert NSInteger to NSNumber
NSInteger intValue = 5;
NSNumber *numberValue = [NSNumber numberWithInteger : intValue];
NSInteger
1)NSInteger is just like a traditional int in C
2)NSInteger can hold an int value or a long value
3)NSInteger is not a class, its primitive
4)NSInteger is nothing more than a 32/64 bit int.
EX- Convert NSNumber to NSInteger
NSInteger myInt = [numberValue integerValue]