I'm trying to create a fixed length string function in swift. I know how it's done in Java for Android but unsure how to translate it to Swift. This is what the Java function looks like:
private String getFixedLengthString(String name, int fixedLength) {
if(name == null) {
name = "";
}
if(name.length() > fixedLength) {
name = name.substring(0, fixedLength);
}
return String.format("%1$-" + fixedLength + "s", name);
}
Any help is appreciated!