Saturday, 29 March 2014

Loading Table view Cell image form URL

 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0) , ^{
                    NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"Image url here"]];
                    if (imgData) {
                        UIImage *image = [UIImage imageWithData:imgData];
                        if (image) {
                            dispatch_async(dispatch_get_main_queue(), ^{
                                MyCustomCell  *cell = (id)[tableView cellForRowAtIndexPath:indexPath];
                                if (cell)

Wednesday, 26 March 2014

@Property Attributes

getter=Use a custom name for the getter method.
setter=Use a custom name for the setter method.
readonlyDon’t synthesize a setter method.
nonatomicDon’t guarantee the integrity of accessors in a multi-threaded environment. This is more efficient than the default atomic behavior.
strongCreate an owning relationship between the property and the assigned value. This is the default for object properties.
weakCreate a non-owning relationship between the property and the assigned value. Use this to prevent retain cycles.
copyCreate a copy of the assigned value instead of referencing the existing instance.


Monday, 24 March 2014

NULL and nil

  • The null pointer is a special kind of pointer that doesn’t point to anything.
  • Pointer can be “emptied” using the null pointer.
  • A good rule of thumb is to use nil for variables that hold Objective-C objects and NULL when working with C pointers.
NSString *anObject;    // An Objective-C object
anObject = NULL;       // This will work
anObject = nil;        // But this is preferred
int *aPointer;         // A plain old C pointer
aPointer = nil;        // Don't do this
aPointer = NULL;       // Do this instead

Monday, 3 March 2014

Find Longitude and Latitude From Address String

 CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    NSString *addressString =@"Apple Inc";
     completionHandler:^(NSArray *placemarks,
                         NSError *error) {
         if (error) {
             NSLog(@"Geocode failed with error: %@", error);
         if (placemarks && placemarks.count > 0)
             CLPlacemark *placemark = placemarks[0];

             CLLocation *location = placemark.location;
             NSLog(@"latitude = %f longitude = %f",location.coordinate.latitude , location.coordinate.longitude);

Location Details From latitude and longitude

CLLocation *location=[[CLLocation alloc] initWithLatitude:48.8582 longitude:2.2945];
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
            NSDictionary *addressDictionary = [[placemarks objectAtIndex:0] addressDictionary];

Setting Region and Annotation in Map View for a coordinate

//Create a coordianate
    CLLocationCoordinate2D coordinate= CLLocationCoordinate2DMake(37.785834,-122.406417);
    //Set region for with the coordiante
    MKCoordinateRegion region =MKCoordinateRegionMakeWithDistance(coordinate, 800, 800);
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
    //add point annotaion to map view
    MKPointAnnotation *point=[[MKPointAnnotation alloc] init];
    point.title=@"hai I am here!!";
    point.subtitle=@"hey how are you?";
    [self.mapView addAnnotation:point];