Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

403
Vistas
Porting JS to swift - Error: No exact matches in call to subscript

This is the JS code:

 const textLength = textContent.length;
    let string = '';
        for (let i = 0; i < textLength; i++) {
          if (string !== '' && offsetsSet.has(i)) {
            parts.push(string);
            string = '';
          }
          string += textContent[i];
        }

This is my swift code which I have ported to swift:

     override func getTextPart() -> String {
        guard let textNode = getLatest() as? TextNode else {
          return text
        }
        return textNode.text
      }
 public func splitText(splitOffsets: [Int]) throws -> [Node] {
      let textContent = getTextPart()
      let textLength = textContent.count
      let offsetsSet = Set(splitOffsets)
      var parts = [String]()
      var string = ""
    
          for i in 0..<textLength {
            if string != "" && offsetsSet.contains(i) {
              parts.append(string)
              string = ""
            }
              string += textContent[i] //Error: No exact matches in call to subscript 
          }
}

I'm getting error in this line: string += textContent[i]//Error: No exact matches in call to subscript. How do I write this in swift?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda