Trim string in ios Swift

func trimString(str : String) -> String
{
    let getstr = str.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
    return getstr
}