Showing posts with label Objective C. Show all posts
Showing posts with label Objective C. Show all posts

Wednesday, 16 March 2016

How to launch Apple Maps from iOS app


applemaps.png

Hi Readers!
Below is the code to launch the Apple Maps application and display the directions between 2 points on Map.
Example 1: Display directions
  1. MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(42.313432,-71.057157) addressDictionary:nil];
  2.   MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark];
  3.   item.name = @"Boston";
  4.  
  5.   MKPlacemark *placemark1 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(35.843871,-78.645056) addressDictionary:nil];
  6.   MKMapItem *item1 = [[MKMapItem alloc] initWithPlacemark:placemark1];
  7.   item1.name = @"Raleigh";

Friday, 8 May 2015

How to get sub strings from a string using Regular Expression

Hi, The below code is to get sub-strings from a string. You are going to love this below code which is very simple but very effective. I have used regular expression to get the sub strings.
  1. NSString *strTest = @"Hii how are you doing @Ravi , how do u do @Kiran where are you @Varun";
  2. NSError *error;
  3. NSRegularExpression *exp =[NSRegularExpression regularExpressionWithPattern:@"@[^ ]*" options:NSRegularExpressionCaseInsensitive error:&error];
  4. NSArray *s1= [exp matchesInString:strTest options:NSMatchingReportCompletion range:NSMakeRange(0, [strTest length]) ];
  5. [s1 enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  6. NSTextCheckingResult *result = obj;
  7. NSString *str = [strTest substringWithRange:result.range];
  8. NSLog(@"str %@",str);
  9. }];

For such more Blogs you can visit to http://findnerd.com/NerdDigest