Usage of NSException in iPhone Apps

In short: Do not use exceptions to indicate anything but unrecoverable errors It is only appropriate to use @try/@catch to deal with unrecoverable errors. It is never appropriate to use @throw/@try/@catch to do control-flow like operations on iOS or Mac OS X. Even then, consider carefully whether you are better off using an exception to … Read more

Catching NSException in Swift

Here is some code, that converts NSExceptions to Swift 2 errors. Now you can use do { try ObjC.catchException { /* calls that might throw an NSException */ } } catch { print(“An error ocurred: \(error)”) } ObjC.h: #import <Foundation/Foundation.h> @interface ObjC : NSObject + (BOOL)catchException:(void(^)(void))tryBlock error:(__autoreleasing NSError **)error; @end ObjC.m #import “ObjC.h” @implementation ObjC … Read more

ERROR SHOWING in program code ios

Try This to select date from date picker… -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { datePicker =[[UIDatePicker alloc]initWithFrame:CGRectMake(50,150,10, 50)]; datePicker.datePickerMode=UIDatePickerModeDate; datePicker.hidden=NO; datePicker.date=[NSDate date]; [datePicker addTarget:self action:@selector(textFieldTitle:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:datePicker]; UIBarButtonItem * rightBtn=[[UIBarButtonItem alloc]initWithTitle:@”Done” style:UIBarButtonItemStyleDone target:self action:@selector(save:)]; self.navigationItem.rightBarButtonItem=rightBtn; return true; } -(void)textFieldTitle:(id)sender { NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init]; dateFormat.dateStyle=NSDateFormatterMediumStyle; [dateFormat setDateFormat:@”MM/dd/yyyy”]; NSString *str=[NSString stringWithFormat:@”%@”,[dateFormat stringFromDate:datePicker.date]]; self.txtField.text=str; } -(void)save:(id)sender { self.navigationItem.rightBarButtonItem=nil; [datePicker removeFromSuperview]; … Read more