Please check where you placed it ... Try putting the code above in
-(void)textFieldDidBeginEditing:(UITextField *)textField { [textField selectAll:self]; }
And also txt should be a UITextField. Also remember to set the delegate for txt as
txt.delegate = self;
where you declared it, and add a UITextFieldDelegate to .h as
@interface ViewController : UIViewController <UITextFieldDelegate>
It will definitely work ... It worked for me ..
source share