Design pattern

Protocols Enable Shared Functionality Across Classes
pets, dogs, birds, flight, bats, insects

UITextFieldDelegateProtocol in Swift

func textField(textField: UITextField,
	shouldChangeCharactersInRange range:NSRange,
		replacementString string: String) -> Bool {
	
		var newText = textField.text! as NSString
		newText =
		newText.stringByReplacingCharactersInRange(range,
			withString: string)

		return newText.length <= 5
}

UITextFieldDelegateProtocol in Objective-C

-(BOOL)textField:(UITextField *)textField
	shouldChangeCharactersInRange:(NSRange)range
		replacementString:(NSString *)string{

		NSString *nexText = textField.text;
		newText = [newText
		stringByReplacingCharactersInRange:range
			withString:string];

		return (newText.length <=5);
}