Guillermo Navarro
Guillermo Navarro

Reputation: 267

cannot convert value of type 'NSString' to type 'String' in coercion swift2 with ubuntu 14.04

i have a problem with swift about the NSString, i'm not an expert with this property and i don't know why cannot convert to string, here is a part of the code:

var countL = LEXEMAS.count-1;
var countP = PATRONES.count-1;

var patternIndex:Int = -1;

for indexL in 0..<countL {
    var input:NSString = NSString(string: LEXEMAS[indexL]);
    var range:NSRange = NSMakeRange(0, input.length)
    TOKENS.append("no existe");

    for indexP in 0..<countP {
        var regex = try? NSRegularExpression(pattern: PATRONES[indexP], options: NSRegularExpressionOptions(rawValue: 0))
        var matches = regex!.matchesInString(LEXEMAS[indexL], options: NSMatchingOptions(rawValue: 0), range: range)

        if matches.count > 0 {
            TOKENS[indexL] = NOMBRES[indexP];
            print(NOMBRES[indexP] + "   " + (input as String) + "\n");
            break;
        }
    }
}

and here is the detail of the error:

main.swift:75:46: error: cannot convert value of type 'NSString' to type 'String' in coercion
            print(NOMBRES[indexP] + "   " + (input as String) + "\n");
                                             ^~~~~

Upvotes: 0

Views: 2541

Answers (1)

Guillermo Navarro
Guillermo Navarro

Reputation: 267

i found the answer, only i had to specify the type of value in the input var, like this:

print(NOMBRES[indexP] + "   " + String(input) + "\n")

Upvotes: 1

Related Questions