Monday, June 23, 2014

Learing Web Links

Differences between strong and weak in objective-c

A strong reference (which you will use in most cases) means that you want to "own" the object you are referencing with this property/variable. The compiler will take care that any object that you assign to this property will not be destroyed as long as you (or any other object) points to it with a strong reference. Only once you set the property to nil will the object get destroyed (unless one or more other objects also hold a strong reference to it).
In contrast, with a weak reference you signify that you don't want to have control over the object's lifetime. The object you are referencing weakly only lives on because at least one other object holds a strong reference to it. Once that is no longer the case, the object gets destroyed and your weak property will automatically get set to nil. The most frequent use cases of weak references in iOS are:
  1. delegate properties, which are often referenced weakly to avoid retain cycles, and
  2. subviews/controls of a view controller's main view because those views are already strongly held by the main view.
atomic vs. nonatomic refers to the thread safety of the getter and setter methods that the compiler synthesizes for the property. atomic (the default) tells the compiler to make the accessor methods thread-safe (by adding a lock before an ivar is accessed) and nonatomic does the opposite. The advantage of nonatomic is slightly higher performance. On iOS, Apple uses nonatomic for almost all their properties so the general advice is for you to do the same.

Monday, February 17, 2014

Push and Pop VC based on Sting Selection




Push to View Controller  based on String 

A ===>VC

.M File

-(void) push
{

VCName *vcobj=[[VCName alloc]initWithNibName:@"VCName" bundle:nil];
 [vcobj setPageString:@"SelectVC"];
    [self.navigationController vcobj animated:YES];


// Example
ArriveTicketViewController *arrivelView=[[ArriveTicketViewController alloc]initWithNibName:@"ArriveTicketViewController" bundle:nil];
 [arrivelView setPageString:@"SelectVC"];
    [self.navigationController pushViewController:arrivelView animated:YES];

}



B ====> VC

.h File

{
NSString *pageString;

}

@property(nonatomic,strong) NSString *pageString;

.M File


@synthesize pageString;


if([self.pageString isEqualToString:@“SelectVC”])
   {
     // perform action
     
   }



Poping the ViewController


-(void)PopToVC
{
    for (UIViewController *viewcontroller in [self.navigationController viewControllers])
    {
        if ([viewcontroller isKindOfClass:[VCName class]])
        {
            VCNameobj =(VCName *)viewcontroller;
            VCNameobj.pageString=@"SelectVC";
            [self.navigationController popToViewController:viewcontroller animated:YES];
        }
    }

}

Sunday, February 16, 2014

Getting Current Location



.h file


    BOOL didFindLocation;

.m file

- (void)viewDidLoad
  [self startFindLocation];

-(void)startFindLocation
{
    self.didFindLocation=NO;
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];

}


#pragma mark Map Current Location=========================


- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
//    UIAlertView *errorAlert = [[UIAlertView alloc]
//                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
//    [errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    
    CLLocation *currentLocation = newLocation;
    
    if (!self.didFindLocation)
    {
        self.didFindLocation = YES;
        [locationManager stopUpdatingLocation];

       self.longitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        self.latitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];

       NSLog(@"strLongitude===%@",self.longitude);
        
        NSLog(@"strLatitude===%@",self.latitude);


    }
    
   

}

NULL Checking For Webservices



#pragma mark ======== Null Checking for web services ===============

+(id)checkForNull:(id)value
{
    NSString *valueString = [NSString stringWithFormat:@"%@",value];
    
    id objectString = @"";
    
    if (![valueString isEqualToString:@"(null)"] && ![valueString isEqualToString:@"<null>"] && valueString.length != 0)
        return value;
    
    return objectString;

}



EX


 [localTrendsData setPhone_number:[self checkForNull:[currentLocalTrends valueForKey:@"phone_number"]]];
            
            [localTrendsData setUser_id:[self checkForNull:[currentLocalTrends valueForKey:@"user_id"]]];
            
            [localTrendsData setCategoryNameArray:[self checkForNull:[currentLocalTrends valueForKey:@"categories"]]];