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