Common method in Swift

1. Check for any field empty in NSDictionary class func checkforEmptyValueinDictioanty(dic:NSDictionary)-> Bool{ for (keyVal, dataVal) in dic {   if (dataVal.length()==0){                 println("\(keyVal): \(dataVal.length())")                 return false             }                 ... Continue Reading →


Use HexColor in Swift as a color

Add it in your class  extension UIColor {    convenience init(red: Int, green: Int, blue: Int) {        assert(red >= 0 && red <= 255, "Invalid red component")        assert(green >= 0 && green <= 255, "Invalid green component")        assert(blue >= 0 && blue <= 255, "Invalid blue... Continue Reading →

Basic HTTP Authentication in iOS while calling webservice

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {    if ([challenge previousFailureCount] == 0) {        NSLog(@"received authentication challenge");        NSURLCredential *newCredential = [NSURLCredentialcredentialWithUser:@"tylerhorne"                                                           ... Continue Reading →

Post Json data to server in iOS

-(void)webservice{ NSString *url= SERVER_URL; NSLog(@"url is %@",url);   NSMutableURLRequest *_request = [NSMutableURLRequestrequestWithURL:[NSURLURLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];   NSMutableDictionary *post=[[NSMutableDictionaryalloc] init]; [post setObject:_emailText.text forKey:@"username"]; [post setObject:_passText.text forKey:@"password"];   NSError *error; NSData *data=[NSJSONSerializationdataWithJSONObject: post options:kNilOptionserror:&error]; NSString *jsonString = [[NSStringalloc] initWithData:data encoding:NSUTF8StringEncoding]; NSString *post = [NSString stringWithFormat:@"json=%@", jsonString]; NSData*postData = [post dataUsingEncoding:NSASCIIStringEncodingallowLossyConversion:NO];   NSLog(@"string is %@",post); [_request setHTTPMethod:@"POST"]; [_request setValue:@"application/x-www-form-urlencoded"forHTTPHeaderField:@"content-type"];... Continue Reading →

Move upward textField in Scrollview when keyboard appears

Step 1>>First add a view in Interface class@property(weak, nonatomic) UIView *activeTextView;Add Notification in ViewWillAppear- (void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    // register for keyboard notifications    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotificationobject:nil];     [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillBeHidden:) name:UIKeyboardDidHideNotificationobject:nil];    }Step 2>>- (void)viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:animated];    // unregister for keyboard notifications    [[NSNotificationCenterdefaultCenter] removeObserver:selfname:UIKeyboardDidShowNotificationobject:nil];    [[NSNotificationCenterdefaultCenter] removeObserver:selfname:UIKeyboardDidHideNotificationobject:nil];    }Step 3>>- (void)textFieldDidBeginEditing:(UITextField *)textField{   ... Continue Reading →

Call a function using Notification in Xcode

Step 1: Post Notification from class A.NSString *data=@"Demo";[[NSNotificationCenter defaultCenter] postNotificationName:@"golferUpdate" object:nil userInfo:data];if you do not want to pass data use [[NSNotificationCenter defaultCenter] postNotificationName:@"golferUpdate" object:nil];Step 2: Register Notification in Class B.[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(GetData:) name:@"golferUpdate"object:nil];Step 3: Add function GetData-(void)GetData:(NSNotification *)notification{    NSDictionary *dict = [notification userInfo];// write your code Here}  Step 4: Enjoy Coding………..Best Of Luck.

Send Class Name as a argument in iOS

Step 1::   in your current class.#import "HomeView.h"#import "MSYCommon.h"Step 2 ::*call this from any method of view where MSYCommon is a name of common class.[MSYCommon pushBackToSpecific:self.navigationController withName:@"HomeView"];Step 3":: in MSYCommon class+(void)pushBackToSpecific:(UINavigationController *)nav withName:(NSString *)screenName{    Class classFromString = NSClassFromString(screenName);    for (UIViewController *controller in nav.viewControllers) {        if ([controller isKindOfClass:[classFromString class]]) {       ... Continue Reading →

Pop to specific View controller in iOS

First Method ::- (void) RetunToSpecificViewController{ for (UIViewController *controller in self.navigationController.viewControllers) { if ([controller isKindOfClass:[AnOldViewController class]]) { //Do not forget to import AnOldViewController.h [self.navigationController popToViewController:controller animated:YES]; break; } } Second Method ::NSArray *array = [self.navigationController viewControllers]; [self.navigationController popToViewController:[array objectAtIndex:2] animated:YES];Best Of Luck.

Live Video Face Masking on iOS

A great post to live video processing

Chris Cavanagh's Blog

Face detection has been possible for some time on iOS thanks to libraries like OpenCV. The CIDetector class introduced in iOS 5 made it a standard feature. Since iOS 7 it can also detect smiles and eye blinks Smile

With iOS 6, AV Foundation gained AVCaptureMetadataOutput, allowing face detection to be included in the capture pipeline (in iOS 7 it also supports barcode scanning).

Here’s how you could use that to perform face masking on live video:


First thing to do is get the capture session set up:

 AVCaptureSession *captureSession = [AVCaptureSession new]; [captureSession beginConfiguration]; NSError *error; // Input device AVCaptureDevice *captureDevice = [self frontOrDefaultCamera]; AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error]; if ( [captureSession canAddInput:deviceInput] ) { [captureSession addInput:deviceInput]; } if ( [captureSession canSetSessionPreset:AVCaptureSessionPresetHigh] ) { captureSession.sessionPreset = AVCaptureSessionPresetHigh; } // Video data output AVCaptureVideoDataOutput *videoDataOutput = [self createVideoDataOutput]; if ( [captureSession canAddOutput:videoDataOutput] ) { [captureSession addOutput:videoDataOutput]; AVCaptureConnection *connection…

View original post 511 more words

Create a free website or blog at

Up ↑

%d bloggers like this: