FormattedStringEditing
public protocol FormattedStringEditing : AnyObject
This is the formatter protocol to handle special formatting of the text used in the UITextField of TextFieldFormCell.
Currently, SAPFiori provides two implementations:
PhoneNumberFormatterto format phone numbers.CustomNumberFormatterto format numbers that uses the regular iOSNumberFormatter.GenericTextFormatterto format any text matching predefined patterns.
-
This function formats the specified string with the specified cursor position then returns the formatted
NSAttributedSteringand the adjusted cursor position.The implementation may return nil for this function. In that case, the caller should expect to use the other function to format the string:
func string(for string: String, cursorPosition: Int) -> (formattedString: String?, adjustedCursorPosition: Int)?Declaration
Swift
func attributedString(for string: String, withDefaultAttributes attrs: [NSAttributedString.Key : Any]?, cursorPosition: Int) -> (formattedAttributedString: NSAttributedString?, adjustedCursorPosition: Int)?Parameters
stringThe original string to be formatted.
attrsThe default attributes for the formatted
NSAttributedString.cursorPositionThe cursor position of a
UITextFieldor other similar UI components.Return Value
A tuple containing the
NSAttributedStringafter format, and the adjusted cursor position. -
This function formats the specified string with the specified cursor position then returns the formatted string and the adjusted cursor position.
Declaration
Swift
func string(for string: String, cursorPosition: Int) -> (formattedString: String?, adjustedCursorPosition: Int)?Parameters
stringThe original string to be formatted.
cursorPositionThe cursor position of a
UITextFieldor other similar UI components.Return Value
A tuple containing the string after format, and the adjusted cursor position.
-
This function returns the string user typed from formatted string.
This function is similar to the function with the same signature as in the standard iOS SDK
Formatter.Declaration
Swift
func editingString(for obj: Any) -> String?Parameters
objThe implementation should expect this to be a
String, representing the formatted string.Return Value
The original string without format.
-
This function checks if the given
partialStringis acceptable to the formatter or not.This function is similar to the function with the same signature as in the standard iOS SDK
Formatter.Declaration
Swift
func isPartialStringValid(_ partialString: String, newEditingString newString: AutoreleasingUnsafeMutablePointer<NSString?>?, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> BoolParameters
partialStringThe string that is to be added to the editing string.
newEditingStringThe current editing string.
errorThis parameter is not used.
Return Value
trueif thepartialStringis to be accepted.