func smallCaps(text:String) -> String{
let map = ["0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9","a":"ᴀ","b":"ʙ","c":"ᴄ","d":"ᴅ","e":"ᴇ","f":"ғ","g":"ɢ","h":"ʜ","i":"ɪ","j":"ᴊ","k":"ᴋ","l":"ʟ","m":"ᴍ","n":"ɴ","o":"ᴏ","p":"ᴘ","q":"ǫ","r":"ʀ","s":"s","t":"ᴛ","u":"ᴜ","v":"ᴠ","w":"ᴡ","x":"x","y":"ʏ","z":"ᴢ","A":"A","B":"B","C":"C","D":"D","E":"E","F":"F","G":"G","H":"H","I":"I","J":"J","K":"K","L":"L","M":"M","N":"N","O":"O","P":"P","Q":"Q","R":"R","S":"S","T":"T","U":"U","V":"V","W":"W","X":"X","Y":"Y","Z":"Z"]
var charArray = text.components(separatedBy: " ")
var i = 0
while i<charArray.count {
i+=1
charArray[i] = map[charArray[i]] ?? text
}
let string = charArray.joined(separator: "")
print(string)
return string
}
smallCaps(text: "hello")
Please clarify what you want to ask.
---
When you show error message, better take more parts of the error info shown in the debug console:
Fatal error: Index out of range
And the exact line number of the error
charArray[i] = map[charArray[i]] ?? text
Your `charArray` is an Array of only one element "hello", but your `i` gets greater than 0.
Thats the reason for the error Index out of range.
But you have no need to (and should not) use `components(separatedBy:)`, so check my answer for you another question.