To check if a string contains only numeric digits in Swift, you can iterate through each character in the string and check if it is a digit using 'Character' properties.
In this example,
func containsOnlyNumericDigits(str: String) -> Bool {
return str.allSatisfy { $0.isNumber }
}
let str = "12345"
let allDigits = containsOnlyNumericDigits(str: str)
print("String contains only numeric digits: \(allDigits)")
String contains only numeric digits: true
In this tutorial, we learned How to Check if String contains only Numeric Digits in Swift language with well detailed examples.