Avatar ·

Como usar String.substringWithRange em Swift? Ou como funcionam Range em Swift?

Olá a todos! Sou novo em Swift, migrando do Objective-C, e estou tendo um problema com manipulação de strings. Em Objective-C, eu facilmente extraía substrings usando `substringWithRange:`, por exemplo: ```objc NSString *str = @"Привет, мир!"; NSRange range = NSMakeRange(0, 6); NSString *substr = [str substringWithRange:range]; // "Привет" ``` Em Swift, estou tentando fazer o mesmo, mas encontro erros. Escrevi: ```swift let str = "Привет, мир!" let range = NSMakeRange(0, 6) let substr = str.substringWithRange(range) // Erro! ``` O Xcode diz que `String` não tem o método `substringWithRange`. Li que em Swift é preciso usar `Range`, mas não entendo como criá-lo. Por que não posso simplesmente passar um `NSRange`? Por favor, expliquem com exemplos: 1.