Wednesday, February 25, 2015

IOS

*****************************Design Pattern*********************

  • Creational: Singleton and Abstract Factory.
  • Structural: MVC, Decorator, Adapter, Facade and Composite.
  • Behavioral: Observer, Memento, Chain of Responsibility and Command.
   
MVC - model , view , controller 
Singleton - one instance exists [UIApplication sharedApplication]
Facade Design - Facebook API
Decorator pattern- Decorator pattern dynamically adds behaviors and responsibilities to an object without modifying its code.implementations of this pattern: Category and Delegation.
category - Category is  that allows you to add methods to existing classes without subclassing
Delegation - , Delegation, is a mechanism in which one object acts on behalf of, or in coordination with, another object

Observer pattern -  one object notifies other objects of any state changes. e.g Notifications and Key-Value Observing
The memento pattern -The memento pattern captures and externalizes an object’s internal state. In other words, it saves your stuff somewhere. Memento pattern is Archiving. NSCoder class


*****************************Dynamic Typing*********************

Dynamic Typing:
Determining class of a Object at runtime is called dynamic typing.
Dynamic binding:
Determining the method to invoke at run time is called dynamic binding. 

*****************************Obj c and c++*********************

Objective C Allows method name and variable name exactly the same.
-It doesn't have the constructor or destructor instead,it has init and dealloc which must be called explicitly.
-It uses '+' and '-' to differentiate factory and instance methods.
-It uses dynamic linking.
-It got categories .


Auto layout - IOS 6

store data - plist , nsuserdefault , sqlite, core data

Shallow copy is also known as address copy.
deep copy you copy data

What is advantage of categories? What is difference between implementing a category and inheritance?
You can add method to existing class even to that class whose source is not available to you. You can extend functionality of a class without subclassing. You can split implementation in multiple classes. While in Inheritance you subclass from parent class and extend its functionality.

polymorphism  - Ability of base class pointer to call function from derived class at runtime is called polymorphism.at runtime, super class reference is pointing to whatever subclass,

App delegate is declared as a subclass of UIResponder 

@interface - It’s a keyword used to declare the Class
@implementation - It’s a keyword used to define the Class
@synthesize - to generate getters and setters automatically from compiler

Atomic and non- atomic -  nonatomic and atomic are related to multithreading environment . If a property has an attribute as “nonatomic” that means multiple threads can modify that property concurrently. If the attribute is “atomic”, the threads would be given access atomically. So “Atomic” is thread safe while “nonatomic” is thread unsafe. 

@ dynamic  - It tells compiler that getter and setter are not implemented by the class but by some other class. e.g The Managed object classes have properties defined by using @dynamic

mustitasking - IOS4

Json - Form iOS 5 Onwards we are using NSJSONSerialization inherited from NSObject Base class.

categories and extensions-  Class extensions are similar to categories. 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.

KVC - KVC(Key Value Coding)  Normally instance variables are accessed through properties or accessors but KVC gives another way to access variables in form of strings.In this way your class acts like a dictionary and your property name.

KVO (Key Value Observation): The mechanism through which objects are notified when there is change in any of property is called KVO.

A protocol, declared with the (@protocol syntax in Objective-C) is used the declare a set of methods that a class that “adopts” .id<MyProtocol> instanceOfClassThatImplementsMyProtocol;protocol Directives :- @optional, @required.

run loop - . A run loop is an event processing loop that you use to schedule work and coordinate the receipt of incoming events. The purpose of a run loop is to keep your thread busy when there is work to do and put your thread to sleep when there is none. Run loop management is not entirely automatic. You must still design your thread’s code to start the run loop at appropriate times and respond to incoming events.










Wednesday, February 11, 2015

NSMutableString to set some part of sting BOLD -- IOS

 NSString *textStr = @"This is a good boy";

NSRange rangeBold = [textStr rangeOfString:@"good"];

 UIFont *changeFont = [UIFont boldSystemFontOfSize:13];
        
  NSDictionary *dictBoldText = [NSDictionary dictionaryWithObjectsAndKeys: changeFont, NSFontAttributeName, nil];
        
 NSMutableAttributedString *mutAttrTextViewString = [[NSMutableAttributedString alloc] initWithString:textStr];
        
  [mutAttrTextViewString setAttributes:dictBoldText range:rangeBold];

        
       

    YOUR_TEXT_VIEW.attributedText = mutAttrTextViewString;

Monday, December 29, 2014

How to Move UITextField Up when Keyboard is Showing -- IOS


-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    [self animateTextField:textField up:YES];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self animateTextField:textField up:NO];
}

-(void)animateTextField:(UITextField*)textField up:(BOOL)up
{
    const int movementDistance = -215; // distance as needed
    const float movementDuration = 0.3f; // distance as needed
    
    int movement = (up ? movementDistance : -movementDistance);
    
    [UIView beginAnimations: @"animateTextField" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    [UIView commitAnimations];

}

Monday, October 13, 2014

Move & Resize textview automatically along with keyboard -- IOS


@property (nonatomic) CGRect originalTextViewFrame;
- (void)viewWillAppear:(BOOL)animated
 {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)viewWillDisappear:(BOOL)animated 
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)keyboardWillShow:(NSNotification*)notification
 {
[self moveTextView:notification up:YES];
}

- (void)keyboardWillHide:(NSNotification*)notification 
{
[self moveTextView:notification up:NO];
}

- (void)moveTextView:(NSNotification*)notification up:(BOOL)up
 {
NSDictionary *userInfo = [notification userInfo];
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardRect;

[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
animationDuration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
keyboardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyboardRect = [self.view convertRect:keyboardRect fromView:nil];

[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];

if (up == YES)
 {
CGFloat keyboardTop = keyboardRect.origin.y;
CGRect newTextViewFrame = textView.frame;
originalTextViewFrame = textView.frame;
newTextViewFrame.size.height = keyboardTop - textView.frame.origin.y - 10;

textView.frame = newTextViewFrame;
}
 else 
{
textView.frame = originalTextViewFrame;
}

[UIView commitAnimations];
}

Saturday, September 27, 2014

Decode image from NSData -- IOS

- (UIImage*)decodeBase64ToImage:(NSString *)strEncodeData
{
    NSData *data = [[NSData alloc]initWithBase64EncodedString:strEncodeData options:NSDataBase64DecodingIgnoreUnknownCharacters];
    return [UIImage imageWithData:data];

}

Wednesday, September 17, 2014

Restrict User to enter only 3 digit in UITextField and not more than 1000 ----> IOS

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if([string length]==0){
        return YES;

    }
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];

//first, check if the new string is numeric only. If not, return NO;
NSCharacterSet *characterSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789,."] invertedSet];
if ([newString rangeOfCharacterFromSet:characterSet].location != NSNotFound)
{
    return NO;
}


return [newString doubleValue] < 1000;
}

Tuesday, September 9, 2014

Add underline on UIButton using Attributed String--- IOS

    NSMutableAttributedString *commentString = [[NSMutableAttributedString alloc] initWithString:@"Terms & Conditions"];
    
    [commentString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [commentString length])];
    

    [_m_btnTnC setAttributedTitle:commentString forState:UIControlStateNormal];