Sunday, January 6, 2013

Some Important Iphone Question Answer

Difference between shallow copy and deep copy?


Ans: Shallow copy is also known as address copy. In this process you only copy address not actual data while in deep copy you copy data.

Suppose there are two objects X and Y. X is pointing to a different array while Y is pointing to different array. Now what I will do is following to do shallow copy.
Char *X = {‘a’,’b’,’c’};
Char *B = {‘r’,’s’,’t’};
Y = A;
Now B is pointing is at same location where A pointer is pointing.Both X and Y in this case sharing same data. if change is made both will get altered value of data.Advantage is that coping process is very fast and is independent of size of array.

while in deep copy data is also copied. This process is slow but Both A and B have their own copies and changes made to any copy, other will copy will not be affected.

What is advantage of categories?

Ans: 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.


What is keyword atomic in Objective C?


Ans: When you place keyword atomic with a property, it means at one time only one thread can access it.


What are mutable and immutable types in Objective C?


Ans: Mutable means you can change its contents later but when you mark any object immutable, it means once they are initialized, their values cannot be changed. For example, NSArray, NSString values cannot be changed after initialized.


Swap the two variable values without taking third variable?


Ans:-
int x=10;
int y=5;
x=x+y;
NSLog(@”x==> %d”,x);
y=x-y;
NSLog(@”Y Value==> %d”,y);
x=x-y;
NSLog(@”x Value==> %d”,x);
Thanks to Subrat for answering this question.

Wednesday, June 20, 2012

Property in iphone


Using @property tells the compiler that you intend to access the corresponding member variable through "setter" and "getter" functions, i.e. functions which change the value of the variable or return its value. The warnings you're seeing are because you have not defined the required functions.
your header (.h) file looks something like this:
@property(readwrite, assign)  myPhoto;
Because you've told the compiler that those variables should be accessible through setter and getter functions, you need to define those functions. There are two ways of doing this. The easiest is to use@synthesize, by adding the following to your implementation (.m) file:
@synthesize myPhoto;
The @synthesize line causes the - myPhoto, - setMyPhoto  methods to be generated automatically at compile time. You may also define those methods manually, but doing so is usually unnecessary.
 Let's have look on following the Album class example to use properties.

Here's what it looked like before:
@interface AlbumController : UIViewController
{
    NSString* albumTitle;
    NSString* albumAuther;
}
- (NSString*) albumTitle;
- (NSString*) albumAuther;

- (void) setalbumTitle: (NSString*)input;
- (void) setalbumAuther: (NSString*)input;
@end

Here's what it looks like once converted to properties:
@interface AlbumController : UIViewController
{  
    NSString* albumTitle;
    NSString* albumAuther;
}
@property(retain)NSString* albumTitle;
@property(retain)NSString* albumAuther;
@end

The @property is an Objective-C directive which declares the property. The "retain" in the parenthesis specifies that the setter should retain the input value, and the rest of the line simply specifies the type and the name of the property. 

Insted of "retain" you can also use following some other keyword.
  • assign - does nothing to reference count simply points your variable to the data
  • retain - points your variable to data and adds 1 to reference count, data is guaranteed to be there while your variable is still alive
  • copy - makes a copy of data, points your variable at it and makes the retain count 1

assign - the ivar is set by doing a simple assignment. Implementation:
- (void) setFoo:(NSString *)newFoo {
  foo = newFoo;
}

retain - the ivar is sent the retain message before doing the assignment. Implementation:
- (void) setFoo:(NSString *)newFoo {
  if (foo != newFoo) {
    [foo release];
    foo = [newFoo retain];
  }
}

copy - the ivar is sent the copy message before doing the assignment. Implementation:
- (void) setFoo:(NSString *)newFoo {
  if (foo != newFoo) {
    [foo release];
    foo = [newFoo copy];
  }
}

Thursday, June 7, 2012

How To Remove Background Of UISearchBar in iphone

To remove background of UISearchBar first set search bar background color clear color putting following  one line code
searchBar.backgroundColor = [UIColor clearColor];

After adding Subview of UISearchBar [self.view addSubview:searchBar];
Then use any one Method following code

Method:1
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
                            OR
Method:2
for (UIView *subview in searchBar.subviews) {

        if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {

            [subview removeFromSuperview];

            break;
        }
    }

Wednesday, June 6, 2012

Automatic Reference Counting (ARC)


What is ARC:       

ARC or automatic reference counting is a new concept that is added in the latest xcode with this feature you need not worry about managing your objects the LLVM 3.0 compiler which is newly added by apple will take care of it.

This means now you don’t have to retain, release or autorelease an object with ARC all this is done for you by the LLVM 3.0 compiler this is something very cool and very neat that apple has done for its developer.


Earlier in objective c we had to do manual memory management which had the below rules:
·         If you need to keep an object around you need to retain it.

·         If you are the owner of an object you will release the object when its not in use.

·         If you want to stop using an object you need to release it, unless you have used autorelease.

Tuesday, April 3, 2012

Units Information

Some Extra Unit informaion

Thursday, November 10, 2011

Create Your OWN Google Style Logo And Search Page

Step1: Open your browser and open following links:
            http://www.goglogo.com/

Step2: Write Your Name in front of "Enter your name ==>" text Field and Click "Create My Search Page" button. wow you will get your own google style logo just like following images.


Wednesday, November 9, 2011

Search Google Images with spins around everything


Go to google.com and search for
" Google Sphere "
Click on first result OR Click on "I'm Feeling Lucky" link
Wow you will get spins everything then click on TextBox and enter text what ever you want to search and press enter.

NOTE: If you have the Chrome browser available, have a great look at Google Sphere.