NSInteger sortByDistance(id obj1, id obj2, void *context) {
NSDictionary *dict1 =(NSDictionary*)obj1;
NSDictionary *dict2 =(NSDictionary*)obj2;
NSInteger num1 = [[dict1 objectForKey:@"distance"] integerValue];
NSInteger num2 = [[dict2 objectForKey:@"distance"] integerValue];
if (num1 < num2)
return NSOrderedAscending;
else if (num1 > num2)
return NSOrderedDescending;
return NSOrderedSame;
}
sortedArray = [anArray sortedArrayUsingFunction:sortByDistance context:nil];
reverseSortArray = [[[anArray sortedArrayUsingFunction:sortByDistance context:nil] reverseObjectEnumerator] allObjects];
Monday, 16 June 2014
Sort array using function
Sort Array
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
sortedArray=[anArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
Random number Between limits
-(NSInteger)randNumberBetween:(NSInteger)min and:(NSInteger)max{
return (rand() % (max - min) + min);
}
Set Font For Bar Button item
UIBarButtonItem *facebook=[[UIBarButtonItem alloc] initWithTitle:@"FB" style:UIBarButtonItemStylePlain target:self action:@selector(postInFb:)];
[facebook setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"icomoon" size:30], NSFontAttributeName,
[UIColor colorWithRed:68.0/255.0 green:85.0/255.0 blue:153.0/255.0 alpha:1], NSForegroundColorAttributeName,
nil]
forState:UIControlStateNormal];
Monday, 19 May 2014
Playing embedded video in iOS
NSString* embeddtext =@"<iframe width=\"560\" height=\"315\" src=\"//www.youtube.com/embed/Neff9scaCCI\" frameborder=\"0\" allowfullscreen></iframe>";
NSLog(@"Full code = %@",embeddtext);
embeddtext = [embeddtext substringFromIndex:[embeddtext rangeOfString:@"src=\""].location+[embeddtext rangeOfString:@"src=\""].length];
embeddtext = [embeddtext substringToIndex:[embeddtext rangeOfString:@"\""].location ];
if([embeddtext rangeOfString:@"http"].location==NSNotFound)
embeddtext=[NSString stringWithFormat:@"http:%@",embeddtext];
NSLog(@"video src = %@",embeddtext);
NSString *html = [NSString stringWithFormat:@"<iframe width=\"300\" height=\"250\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>",embeddtext];
[webView loadHTMLString:html baseURL:[NSURL URLWithString:nil]];
Thursday, 15 May 2014
Rendering Microsoft Files in Using Office Web App.
NSString *fileUrl;// .doc .docx, .ppt, .pptx, .xls, .xlsx files
fileUrl=[fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://view.officeapps.live.com/op/view.aspx?src=%@",fileUrl]]]];
Wednesday, 14 May 2014
Url Special Characters encoding
NSString *str=@"!*'();:@&=+$,/?%#[]";//put the url here...
NSString *encodedStr=(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)str,
NULL,
CFSTR("!*'();:@&=+$,/?%#[]"),
kCFStringEncodingUTF8));
NSLog(@"after encoding = %@",encodedStr);
Subscribe to:
Posts (Atom)